我在ubuntu下安装了QT5.5,然后写了一个关于U盘热插拔识别的程序,在代码中想通过QDBusInterface来查看org.freedesktop.Hal服务关于U盘的插拔事件,但是在进行 dBusInterface->isValid() 判断时 却提示找不到这个服务,这是什么原因呢?
参照博文 http://rys1314520.iteye.com/blog/1820819
代码如下
     dBusInterface = new QDBusInterface(DBUS_HAL_SERVICE,
                                                       DBUS_HAL_PATH,
                                                     DBUS_HAL_INTERFACE,
                                                   QDBusConnection::systemBus(),
                                                    this);
    QTextCodec *tc = QTextCodec::codecForLocale();
    if(!dBusInterface->isValid())
      qDebug()<<tc->toUnicode("初始化错误,找不到 dBusInterface!")<<QDBusConnection::systemBus().lastError().message();
    connect(dBusInterface, SIGNAL(DeviceAdded(QString)), this, SLOT(slotDeviceAdded(QString)));
    connect(dBusInterface, SIGNAL(DeviceRemoved(QString)), this, SLOT(slotDeviceRemoved(QString)));程序运行信息:"初始化错误,找不到 dBusInterface!" "The name org.freedesktop.Hal was not provided by any .service files"
QObject::connect: No such signal QDBusAbstractInterface::DeviceAdded(QString) in ../sdflash/mainwindow.cpp:66
QObject::connect:  (receiver name: 'MainWindow')
QObject::connect: No such signal QDBusAbstractInterface::DeviceRemoved(QString) in ../sdflash/mainwindow.cpp:67
QObject::connect:  (receiver name: 'MainWindow')