qtqt-slotqtremoteobjects

Is it possible to get a return value from a QRemoteObject Dynamic Replica slot?


I am unable to call a slot returning a value on a QRemoteObjectDynamicReplica.

It seems that InvokeMethod on Replica doesn't support return value. I have only succeeded in calling void returning slots and even in this case, in DirectConnection mode, the invokeMethod finished before host slot invocation, so it seems that no host answer is in waiting.

I have a code like this which works perfectly on Host side, but not on Replica Side.

  bool success = QMetaObject::invokeMethod(_replica,"getName", Qt::DirectConnection,
      Q_RETURN_ARG(QString, retVal),
      Q_ARG(QString, "id")
   );

If i understand well the topic of REPC (i haven't try it yet), it seems that the calling of returning value slots is possible: Usage is to declare SLOT followed by the desired signature wrapped in parentheses. The return value can be included in the declaration. If the return value is skipped, void will be used in the generated files.

Do REPC do some kind of magic to allow this feature, or did i miss something ?

Thanks for help.


Solution

  • For those who are looking for an answer on this, there is a way :) : the

    QRemoteObjectPendingCall

    undocumented argument.

    bool success = QMetaObject::invokeMethod(_replica,"getName",Qt::DirectConnection,
        Q_RETURN_ARG(QRemoteObjectPendingCall, call),
        Q_ARG(QString, "id")
     );
    auto e = call.error();// , QRemoteObjectPendingCall::InvalidMessage);
    
    call.waitForFinished();
    
    //QVERIFY(call.isFinished());
    
    qDebug() << QMetaType::typeName(call.returnValue().type());
    
    QString retVal = call.returnValue().toString();
    

    This is exactly the same kind a future object available for REPC Replica (except not templated) No Documentation but there is some example in : Qt Remote Objects integration tests

    Sadly, there is currently (5.13.0) no way to get the pending reply in QML (QTBUG-77178) but Qt People are looking for it.