Results 1 to 3 of 3

Thread: QTDbus, Accessing array element in dbus reply message

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2012
    Posts
    5
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QTDbus, Accessing array element in dbus reply message

    Hi,
    Im calling a method using qt dbus, the method call returns array of integers as reply, but im not able to access the array elements.

    this is my method call,
    <code>
    QDBusMessage reply = interface->call("ReadDbusConfigFile");
    qDebug() << "reply :" << reply;
    qDebug() << "reply arguments : " << reply.arguments();
    qDebug() << "reply[0] :" << reply.arguments().at(0);
    </code>

    this is the output,
    reply : QDBusMessage(type=MethodReturn, service=":1.130", signature="ai", contents=([Argument: ai {2, 4}]) )
    reply arguments : (QVariant(QDBusArgument, ) )
    reply[0] : QVariant(QDBusArgument, )

    i want to access value inside array of intiger i.e. 2 and 4,
    but using this "reply.arguments().at(0)" call im getting output as "QVariant(QDBusArgument, )"
    what call i need to use to access those element.

    thanks.

  2. #2
    Join Date
    Feb 2012
    Posts
    5
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QTDbus, Accessing array element in dbus reply message

    Im able to read using below code,

    <code>
    QList<int> ReceivedValue;

    QDBusMessage reply = interface->call("method");
    if (reply.type() == QDBusMessage::ReplyMessage)
    {

    // If it is the reply we expect, it should be a QDBusArgument
    if (reply.arguments().at(0).canConvert<QDBusArgument> ())
    {


    // That contains an Array of QList<int> holding our received values.
    QDBusArgument myArg = reply.arguments().at(0).value<QDBusArgument>();
    if (myArg.currentType() == QDBusArgument::ArrayType)
    {
    myArg.beginArray();

    // Get memory for our resulting values.
    while (!myArg.atEnd())
    {
    int myElement = qdbus_cast<int>(myArg);
    ReceivedValue.append(myElement);
    }
    //myArg.endArray();
    }
    }
    }
    </code>

  3. #3
    Join Date
    Jul 2010
    Posts
    3
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTDbus, Accessing array element in dbus reply message

    QDBusArgument has to be declared as const and myArg.endArray() should not be in comments because the program will leak. Resources allocated in beginArray() are not freed if you don't call endArray().

Similar Threads

  1. Accessing C++ Element exposed for QML in C++
    By Rocken in forum Qt Quick
    Replies: 1
    Last Post: 22nd February 2012, 13:12
  2. <QtDBus/QtDBus> / <dbus/dbus.h>
    By migel in forum Newbie
    Replies: 3
    Last Post: 3rd August 2011, 15:09

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.