0

I'm beginner to Qt.I thought to use QDbusConnection API to get information about device connected. I used following code

#include <QtCore/QDebug>
#include <QtGui/QApplication>



#include <QtDBus/QDBusConnection>

#define HAL_SERV      "org.freedesktop.Hal"
#define HAL_MGR_INT   "org.freedesktop.Hal.Manager"
#define HAL_DEV_INT   "org.freedesktop.Hal.Device" 

#define HAL_MGR_PATH  "/org/freedesktop/Hal/Manager"
#define HAL_DEVS_PATH "/org/freedesktop/Hal/devices"

class Hal : public QObject
{                         
        Q_OBJECT        

public:
        Hal() : 
                QObject(),
                cnx( QDBusConnection::connectToBus( QDBusConnection::SystemBus,     "system" ) )
        {
                cnx.connect(
                                HAL_SERV, HAL_MGR_PATH, HAL_MGR_INT, "DeviceAdded",
                                this, SLOT(added(QString)) );
                cnx.connect(
                                HAL_SERV, HAL_MGR_PATH, HAL_MGR_INT, "DeviceRemoved",
                                this, SLOT(removed(QString)) );
        }

private slots:
        void added( QString dev )
        {
                qDebug() << __FUNCTION__ << dev;
        }

        void removed( QString dev )
        {
                qDebug() << __FUNCTION__ << dev;
        }

private:
        QDBusConnection cnx;
};

int main( int ac, char * * av )
{
        QApplication  app( ac, av );

        Hal hal;

        return( app.exec() );
}

#include "main.moc"

I build the project successfully,If I run I'm not observing any output. and Debugger showing warning like below : GDB: Failed to set controlling terminal: Inappropriate ioctl for device\n"

What is the problem ,can anyone explain me in detail. how to run the application?should I need to any arguments?

Regards, Sujatha

4

1 回答 1

1

尝试使用libusb

有关如何获取附加/分离 USB 设备事件的示例在这里

于 2013-10-15T06:42:23.480 回答