Unsolved QDBusReply::operator Type() const usage
-
Hello,
I'm trying to follow this example in the QDBusReply documentation.
If the remote method call cannot fail, you can skip the error checking:
QString reply = interface->call("RemoteMethod");
But this example does not compile for me. Am I missing something?
There is overloaded operator QDBusReply::operator Type() const. And closest I could get to example that compiles is:QString reply = QDBusReply<QString>(interface->call("RemoteMethod"));
-
@Eligijus What example do you mean? If it does not compile: what is the compiler error?
-
Sorry I had a wrong link in QDBusReply documentation it's fixed now.
Error:/home/eligijus/BigDisk/QtProjects/bigbrother2/gui_application/systemd1service.cpp:510: error: conversion from ‘QDBusMessage’ to non-scalar type ‘QString’ requested QString s = call("GetDefaultTarget"); ^
-
@Eligijus Why are you trying to cast QDBusMessage to a QString? What do you want to achieve?
-
@jsulm I'm trying to follow an example from here http://doc.qt.io/qt-5/qdbusreply.html#details
Detailed Description
The QDBusReply class stores the reply for a method call to a remote object.A QDBusReply object is a subset of the QDBusMessage object that represents a method call's reply. It contains only the first output argument or the error code and is used by QDBusInterface-derived classes to allow returning the error code as the function's return argument.
It can be used in the following manner:
QDBusReply<QString> reply = interface->call("RemoteMethod"); if (reply.isValid()) // use the returned value useValue(reply.value()); else // call failed. Show an error condition. showError(reply.error());
If the remote method call cannot fail, you can skip the error checking:
QString reply = interface->call("RemoteMethod");
However, if it does fail under those conditions, the value returned by QDBusReply::value() is a default-constructed value. It may be indistinguishable from a valid return value.
QDBusReply objects are used for remote calls that have no output arguments or return values (i.e., they have a "void" return type). Use the isValid() function to test if the reply succeeded.
And my code
QString s = call("GetDefaultTarget");
(it's the same asQString reply = interface->call("RemoteMethod");
) does not compile