PDA

View Full Version : howto send a reply using QDBusMessage



HERC
23rd February 2010, 15:30
Hello,

I want to send a reply over DBUs before the end of my slot method. According to the QT document I have to use QDBusMessage QDBusMessage::createReply ( const QVariant & argument ) const.

Suppose I have the follow slot

int getValue(QString key);

How can I send a reply over the DBUS? I tried it like this


Int getValue(QString key) {
QDBusMessage msg;
QVariant v(2);
msg.createReply(v)
bus.send(msg);

Return 0;
}

Where
bus= QDBusConnection::sessionBus();

But I get the follow DBUS error
QDBusConnection: error: could not send invalid message to service “”

HERC
23rd February 2010, 17:24
it seems that I have to implement the follow slot


int getValue(QString key,const QDBusMessage&);

and the slot implemantation is


int getValue(QString key,const QDBusMessage& msg) {

QVariant v(2);
QDBusMessage reply= msg.createReply(v)
QDBusConnection::sessionBus().send(reply);

Return 0;
}

However I recevied 2 replys in that case .
According to the QT document no reply should be send on return.

HERC
23rd February 2010, 17:32
I have to set



msg.setDelayedReply(true);