[Qt-interest] Using callWithCallback() in QtDBus

Paddy Carman paddy.carman at gmail.com
Fri Oct 1 00:37:22 CEST 2010


Hi All,
    I'm new to Qt programming. I'm also trying to use QtDBus.  I was able to
compile and run the "Complex Ping Pong" example.  I wanted to modify the
example and use callWithCallback() as I wanted to keep the client and server
communication completely asynchronous. My modifications are shown below:

1. Added new function
    void Ping::processReply(const QDBusMessage& reply)
    {
       printf("Got Reply\n");
    }

2. Replaced following 3 lines in function Ping::begin
    QDBusReply<QDBusVariant> reply = iface->call("query", line);
    if (reply.isValid())
       printf("Reply was: %s\n",
qPrintable(reply.value().variant().toString()));

   with:
    QList<QVariant> args;
    args.append(line);
    QString q("query");
    iface->callWithCallback(q, args, this, SLOT(processReply(const
QDBusMessage&)));

I'm able to compile and run the modified program. However, it looks like the
callback to Ping::processReply() happens only when the loop in Ping::begin
function ends (when the user types an empty line).  I've pasted the program
output below. Note the print messages in the processReply() function only in
the end.

Could someone please explain the problem? What do I need to do to make the
callback happen immediately when the dbus reply arrives?

Thanks in advance!
PC

Program Output:
----------------
$ ./complexping
Connecting to deprecated signal
QDBusConnectionInterface::serviceOwnerChanged(QString,QString,QString)
Got remote interface
Ask your question: hello
Ask your question: what's going on?
Ask your question:
Got Reply
Got Reply
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100930/58e048ac/attachment.html 


More information about the Qt-interest-old mailing list