c++qtpidginqdbus

QDbus: Service Call Returning QList<int>


I'm running into difficulty retrieving values from a service call that is supposed to return an array of integers. The method call in the interface xml file is defined as:

<method name="PurpleFindBuddies">
    <annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="QList&lt;int>"/>
    <arg name="accountId" type="i" direction="in" />
    <arg name="screenName" type="s" direction="in" />
    <arg name="buddies" type="ai" direction="out" />
</method>

qdbusxml2cpp generates the following method:

 inline QDBusPendingReply<QList<int> > PurpleFindBuddies(int accountId, const QString &screenName)
{
    QList<QVariant> argumentList;
    argumentList << QVariant::fromValue(accountId) << QVariant::fromValue(screenName);
    return asyncCallWithArgumentList(QLatin1String("PurpleFindBuddies"), argumentList);
}

I have also added

Q_DECLARE_METATYPE(QList<int>)

at the top of the generated .h file. And in main.cpp, I'm making the following call

QDBusPendingReply<QList<int> > buddies = pidgin->PurpleFindBuddies(accountId, "email@gmail.com");
buddies.waitForFinished();

if ( buddies.isError() ) {
    qDebug() << buddies.error();
    return -1;
}

qDebug() << buddies.argumentAt(0).toList().size();

When I launch the program, I can see from the enabled debug output that I am getting results, as shown below, but the qDebug() line prints 0. I cannot figure out how to correctly retrieve the results.

QDBusConnectionPrivate(0x138fbc0) got message reply (async): QDBusMessage(type=MethodReturn, service=":1.135", signature="ai", contents=([Argument: ai {859}]) )

What am I missing? Any assistance would be greatly appreciated.


Solution

  • So apparently everything was configured correctly. However, when trying to retrieve the data, instead of doing:

    qDebug() << buddies.argumentAt(0).toList().size();
    

    I should have been doing:

    qDebug() << QString::number(buddies.value().size());
    

    To retrieve the individual ids

    foreach(int id, buddies.value() )
        qDebug() << QString::number(id);
    // or simply
    QList<int> ids = buddies.value();