Solved QDBus register type `QMap<QString,QString>'
-
When I use QDBus to call function,it remind me that:
QDBusMarshaller: type `QMap<QString,QString>' (1045) is not registered with D-BUS. Use qDBusRegisterMetaType to register it
QDBusConnection: error: could not send message to service "org.ofono" path "/" interface "org.ofono.VoiceCallManager" member "Dail": Marshalling faild: Unregistered type QMap<QString,QString> passed in arguments
void ofono::Dial() "Marshalling failed: Unregistered type QMap<QString,QString> passed in arguments"But I don't konw how to register type `QMap<QString,QString>' .
Best Wishes.
code_textQDBusInterface interfaceOfono("org.ofono", "/", "org.ofono.VoiceCallManager", QDBusConnection::systemBus()); QDBusMessage msg; QList<QVariant> param; QMap<QString, QString> map; QString number = "xxxxxxxxxxx"; map.insert("number", number); qDebug() << "telephone number: " << number; QVariant var = QVariant::fromValue(map); msg = interfaceOfono.call(QDBus::Block, "Dail", var);
-
@xixi_cly The error already suggests to use qDBusRegisterMetaType. Did you read its documentation: https://doc.qt.io/qt-5/qdbusargument.html#qDBusRegisterMetaType ? It even has an example.
-
@jsulm May I should use Q_DECLARE_METATYPE() first,then register it with qDBusRegisterMetaType<MyClass>();?
I have tried this:#include <QDBusMetaType> #include <QMetaType> Q_DECLARE_METATYPE(QMap(QString, QString)) qDBusRegisterMetaType<QMap(QString, QString)>();
But it's not right.
-
@xixi_cly said in QDBus register type `QMap<QString,QString>':
qDBusRegisterMetaType<QMap(QString, QString)>();
This is wrong. Should be:
qDBusRegisterMetaType<QMap<QString, QString>>();
-
@jsulm There are also some errors:
D:\Demo\qt\phonebook\ofono.cpp:11: error: C++ requires a type specifier for all declarations
D:\Demo\qt\phonebook\ofono.cpp:11: error: template specialization requires 'template<>' -
@xixi_cly Then change it to
qDBusRegisterMetaType<QMap<QString, QString> >();
You seem to use an older C++ compiler, newer compiler can handle >> in template definitions just fine.
-
@jsulm Thank you.After put it in the function, I have solved the problem.