PDA

View Full Version : Qt on maemo DBus



mrudulpen
14th March 2009, 18:09
Hi,

I am trying to use Qt4 on maemo 4.x. (I am an absolute beginner to linux world.)

I am trying to capture event when the device goes in dimmed state. I understand we need to use DBus for it.
Following is the information I get when dbus-monitor is run on the device

signal sender=:1.5 -> dest=(null destination) path=/com/nokia/mce/signal; interface=com.nokia.mce.signal; member=display_status_ind
string "dimmed"

based on that I am writing following code


bool success = conn.connect("com.nokia.mce.signal","/com/nokia/mce/signal","com.nokia.mce.signal", "display_status_ind",halObj, SLOT(listenInactivity(string)));
qDebug() << "SUCCESS : " << success;

where halObj class is as follows

class HalObj : public QObject
{
Q_OBJECT
public:
HalObj (QObject * parent = 0);
virtual ~ HalObj() {}
public slots:
void listenInactivity(QString aStr);
};


But for some reason, my slot never gets called. Also second problem, that I am facing is that, I want to listen for this signal continuously, but it seems, I dont seem to loop by itself, I need to wrap my function call in an infinite while loop.
Here is my main.cpp



void fun()
{
qDebug()<<"Step1";
//Step 1
/* Register previously declared types with DBus */
qDBusRegisterMetaType<Property>();
qDBusRegisterMetaType< QList<Property> >();
qDebug()<<"Step2";
//Step 2
/* This object is used to listen for and react to events */
HalObj * halObj = new HalObj();

/* HAL stores everything on the system bus */
QDBusConnection conn = QDBusConnection::systemBus();

/* Connect to the HAL Manager device to find all devices */
QDBusInterface battery("com.nokia.bme.signal","/com/nokia/bme/signal","com.nokia.bme.signal",conn);

qDebug()<<"Step5";
//Step 5
/* Listen for any ’display_status_ind’ events from this battery
* on DBus
*/
bool success = conn.connect("com.nokia.mce.signal","/com/nokia/mce/signal","com.nokia.mce.signal", "display_status_ind",halObj, SLOT(listenInactivity(string)));
qDebug() << "SUCCESS : " << success;

qDebug()<<"Step7";
}

int main(int argc, char *argv[])
{
while(1)
{
fun();
sleep(2);
}
QCoreApplication a(argc, argv);
return a.exec();
}


Please let me know how to go about this problem.

Another signal I am looking for is charger connected.
The DBus monitor shows following:

signal sender=:1.2 -> dest=(null destination) path=/com/nokia/bme/signal; interface=com.nokia.bme.signal; member=charger_connected
My question is
In the above signal,
Service is: com.nokia.bme.signal
Path is: /com/nokia/bme/signal
Interface is: com.nokia.bme.signal
Method/Signal is : charger_connected
Parameter to slot: void

Is my assumption correct?

any help would be highly appreciated

Kind Regards

Mrudul

mrudulpen
16th March 2009, 12:14
Hi,

Found the solution to this.

Problem was with the path of Signal that was specified. It needs to be ""

Also no need of Interface. One can directly connect to system or session bus.

Regards

Mrudul