Qt d-bus don't receive signal form udisks



  • Hello All,

    I try to handle usb devices changes (remove/add). It's my code:

    /.h/
    @
    #ifndef UDISKS_H
    #define UDISKS_H

    #include <QObject>
    #include <QDBusObjectPath>

    class UDisks : public QObject
    {
    Q_OBJECT

    public:
    UDisks(QObject *parent = 0);

    public slots:
    void device_added(QDBusObjectPath);
    void device_removed(QDBusObjectPath);
    };

    #endif // UDISKS_H
    @

    /.cpp/
    @
    #include "udisks.h"

    #include <QtDBus>
    #include <QDebug>

    const char *udisk_srv = "org.freedesktop.UDisks";
    const char *udisk_path = "/org/freedesktop/UDisks";
    const char *udisk_iface = "org.freedesktop.UDisks";
    const char *udisk_devadd = "DeviceAdded";
    const char *udisk_devrmv = "DeviceRemoved";
    const char *udisk_devsig = "o";

    UDisks::UDisks(QObject *parent) : QObject(parent)
    {
    qDebug() << "added was connected: "
    << QDBusConnection::systemBus().connect(udisk_srv, udisk_path, udisk_iface, udisk_devrmv,
    this, SLOT(device_added(QDBusObjectPath)));

    qDebug() << "removed was connected: "
             << QDBusConnection::systemBus().connect(udisk_srv, udisk_path, udisk_iface, udisk_devrmv,
                                         this, SLOT(device_removed(QDBusObjectPath)));
    

    }

    void UDisks::device_added(QDBusObjectPath)
    {
    qDebug() << "adedd";
    }

    void UDisks::device_removed(QDBusObjectPath)
    {
    qDebug() << "removed";
    }
    @

    /main/
    @
    #include <QCoreApplication>

    #include "udisks.h"

    int main(int argc, char *argv[])
    {
    QCoreApplication a(argc, argv);

    UDisks udisks;
    
    return a.exec&#40;&#41;;
    

    }
    @

    But its not work when I add or remove some USB device.
    Some additional info: Ubuntu 12.04 x64, Qt 5.1.0, gcc x64.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.