我正在尝试编写一个简单的Qt5.2程序,该程序使用libnm-qt5& libmm-qt5来管理连接,但当我试图用这段代码列出它们时:
#include <arpa/inet.h>
#include <QtCore/QTextStream>
#include <NetworkManagerQt5/manager.h>
#include <NetworkManagerQt5/device.h>
#include <NetworkManagerQt5/activeconnection.h>
#include <NetworkManagerQt5/connection.h>
QString typeAsString(const int type)
{
switch (type) {
case 0x0: return QString("Unknown");
case 0x1: return QString("Ethernet");
case 0x2: return QString("Wifi");
case 0x3: return QString("Unused1");
case 0x4: return QString("Unused2");
case 0x5: return QString("Bluetooth");
case 0x6: return QString("OlpcMesh");
case 0x7: return QString("Wimax");
case 0x8: return QString("Modem");
}
return QString("Unknown");
}
int main()
{
QTextStream qout(stdout, QIODevice::WriteOnly);
NetworkManager::Device::List list = NetworkManager::networkInterfaces();
foreach (NetworkManager::Device *dev, list) {
qout << dev->uni() << "\n";
我在QtCreator中收到错误:“/ home /me / Qt / 5.2.1 / gcc_64 /include / QtCore / qglobal.h:860:错误:无法将'const QSharedPointer'转换为'NetworkManager :: Device * '初始化 for(variable = * container .i ;; extension ({ - container .brk; break;})) ^“
我一直在搜索tis:https://build.merproject.org/package/view_file?file=enable-contour.patch&package=plasma-mobile&project=home%3Awonko%3Apa-devel-contour-hack&rev=21这样的知识库,他们使用:
NetworkManager::Device::List iflist = NetworkManager::networkInterfaces();
foreach (NetworkManager::Device::Ptr iface, iflist){
}
但它也给了我错误。有谁知道正确的解决方案?
感谢。
答案 0 :(得分:1)
尝试替换
foreach (NetworkManager::Device *dev, list) { ...
用这个:
foreach (NetworkManager::Device::ptr dev, list) { ...