Details
-
Bug
-
Resolution: Invalid
-
Not Evaluated
-
None
-
5.15.7, 6.5.0
-
None
Description
It seems to me that it's not possible to write a QDBusArgument operator that sends a QDBusArgument-supported type as a D-Bus variant.
I'm trying to write the following operator:
QDBusArgument &operator<<(QDBusArgument &arg, const QJsonObject &json);
and I have written the function to send a QJsonValue already. My tentative implementation is this one:
QDBusArgument &operator<<(QDBusArgument &arg, const QJsonObject &object) { arg.beginMap(QMetaType::QString, qMetaTypeId<QDBusVariant>()); for (auto i = object.begin(); i != object.end(); i++) { arg.beginMapEntry(); arg << i.key() << i.value(); // I have the operator for QJsonValue arg.endMapEntry(); } arg.endMap(); return arg; }
At runtime this doesn't work, because QtDBus complains that while I claimed to send an "a{sv}", at the point when it was expecting the "v" it actually got a basic type (because indeed, my operator for QJsonValue sends the basic type, if that's what it holds). My following attempt, then, is to wrap the value in a QDBusVariant:
QDBusArgument &operator<<(QDBusArgument &arg, const QJsonObject &object) { arg.beginMap(QMetaType::QString, qMetaTypeId<QDBusVariant>()); for (auto i = object.begin(); i != object.end(); i++) { arg.beginMapEntry(); QDBusArgument variant; variant << i.value(); arg << i.key() << QDBusVariant(variant.asVariant()); arg.endMapEntry(); } arg.endMap(); return arg; }
but this also fails (QDBusArgument: read from a write-only object). Unless I'm mistaken, QDBusArgument lacks a beginVariant() method, because I can't seem to be able to find a way to encode into a variant a type that is supported by QDBusArgument.