PDA

View Full Version : qdbus connect return always FALSE



ciberkids
16th September 2009, 17:43
hi to all, this is my first post, i'm developing an program in qt4 and i want to attach it to the dbus daemon...

i have using this method:


halconnection = new QDBusInterface(HAL_SERVICE,HAL_PATH,HAL_INTERFACE, QDBusConnection::systemBus());
//check if the connection is valid
//sorround this with an try cath interface for emit the error and exit
if(halconnection->isValid())
{
Logger::instance()->threadLogDebug(QString(__FUNCTION__),QString("%1").arg(__LINE__),"Dbus interface correctly created");
} else
Logger::instance()->threadLogDebug(QString(__FUNCTION__),QString("%1").arg(__LINE__),"Dbus interface problem");

QDBusReply<QStringList> allDevicesReply = halconnection->call("GetAllDevices");
allDevicesReply.isValid() ? Logger::instance()->threadLogDebug(QString(__FUNCTION__),QString("%1").arg(__LINE__),"All devices were recieved") :
Logger::instance()->threadLogDebug(QString(__FUNCTION__),QString("%1").arg(__LINE__),"Cannot receive all devices");


where :

// Hal constants
#define HAL_SERVICE "org.freedesktop.Hal"
#define HAL_PATH "/org/freedesktop/Hal/Manager"
#define HAL_INTERFACE "org.freedesktop.Hal.Manager"
#define HAL_DEVICE_INTERFACE "org.freedesktop.Hal.Device"

this all works graeat but i have problem at this point:


...
qDebug() << "connection to hal DeviceAdded: "<<halconnection->connection().connect(HAL_SERVICE,HAL_PATH,HAL_INTE RFACE,
"DeviceAdded",this,SLOT(addNewDevice(const QString&)));
qDebug() << "connection to hal DeviceRemoved: "<< halconnection->connection().connect(HAL_SERVICE,HAL_PATH,HAL_INTE RFACE,
"DeviceRemoved",this,SLOT(removedDevice(const QString&)));
qDebug() << "connection to hal is connected: " << halconnection->connection().isConnected();
qDebug() << "connection to hal is valid: " << halconnection->isValid();


this is the output:



connection to hal DeviceAdded: false
connection to hal DeviceRemoved: false
connection to hal is connected: true
connection to hal is valid: true


so i can't connect to the dbus and when a new device is attached my program is never advised by dbus...
the class is called hub and have as super type QThread...
can any help me??

ps. all code compile well... but the problem is at runtime :(

adrian5632
16th September 2009, 18:35
Use:

connect(QString(), QString(), HAL_INTERFACE, "DeviceAdded", this, SLOT(addNewDevice(QString)));

instead of


connect(HAL_SERVICE,HAL_PATH,HAL_INTERFACE, "DeviceAdded",this,SLOT(addNewDevice(const QString&)));

and so on.

ciberkids
16th September 2009, 18:42
i have used this:


qDebug() << "connection to hal DeviceAdded: "<<halconnection->connection().connect(QString(),QString(),HAL_INTER FACE,
"DeviceAdded",this,SLOT(addNewDevice( QString)));


but the output is the same:(



connection to hal DeviceAdded: false
connection to hal DeviceRemoved: false
connection to hal is connected: true
connection to hal is valid: true

ciberkids
17th September 2009, 02:24
i have just re-read my last post.. i have wring pasted the code... i'm sorry..

the code is:


qDebug() << "connection to hal DeviceAdded: "<< halconnection->connection().connect(QString(HAL_SERVICE),
QString(HAL_PATH), QString(HAL_INTERFACE),
QString("DeviceAdded"), this, SLOT(addNewDevice(const QString)));


but the problem are the same... is doesn't conect to the dbus signal and return false..

any can explain me where i'm wrong??

ciberkids
17th September 2009, 15:17
i also tryed this:



qDebug() << "connection to hal DeviceAdded: "<< halconnection->connection().connect(QString(), QString(), HAL_INTERFACE,
"DeviceAdded", this, SLOT(addNewDevice(QString)));


where the define od device added in .h file is:


private slots:
void addNewDevice(QString deviceUdi);


following the API REFERENCE:

bool QDBusConnection::connect ( const QString & service, const QString & path, const QString & interface, const QString & name, QObject * receiver, const char * slot )

Connects the signal specified by the service, path, interface and name parameters to the slot slot in object receiver. The arguments service and path can be empty, denoting a connection to any signal of the (interface, name) pair, from any remote application.

Returns true if the connection was successful.

but the output is always the same:


connection to hal DeviceAdded: false
connection to hal is connected: true
connection to hal is valid: true




i have really need of help, i have tried out all combination of arguments with the same result...

i have controlled with:


[matteo@devel Build]$ qdbus --system org.freedesktop.Hal /org/freedesktop/Hal/Manager
method QString org.freedesktop.DBus.Introspectable.Introspect()
method void org.freedesktop.Hal.Manager.AcquireGlobalInterface Lock(QString interface_name, bool exclusive)
method void org.freedesktop.Hal.Manager.CommitToGdl(QString temporary_udi, QString global_udi)
signal void org.freedesktop.Hal.Manager.DeviceAdded(QString udi) <---------
method bool org.freedesktop.Hal.Manager.DeviceExists(QString udi)
signal void org.freedesktop.Hal.Manager.DeviceRemoved(QString udi)
method QStringList org.freedesktop.Hal.Manager.FindDeviceByCapability (QString capability)
method QStringList org.freedesktop.Hal.Manager.FindDeviceStringMatch( QString key, QString value)
method QStringList org.freedesktop.Hal.Manager.GetAllDevices()
signal void org.freedesktop.Hal.Manager.GlobalInterfaceLockAcq uired(QString interface_name, QString lock_holder, int num_locks)
signal void org.freedesktop.Hal.Manager.GlobalInterfaceLockRel eased(QString interface_name, QString lock_holder, int num_locks)
signal void org.freedesktop.Hal.Manager.NewCapability(QString udi, QString cap_name)
method QString org.freedesktop.Hal.Manager.NewDevice()
method void org.freedesktop.Hal.Manager.ReleaseGlobalInterface Lock(QString interface_name)
method void org.freedesktop.Hal.Manager.Remove(QString udi)
method void org.freedesktop.Hal.Manager.SingletonAddonIsReady( QString command_line)


where i can see the signal...
i doesn't know where i can search/try for this... :confused: