Re: [RAUC] Antwort: D-Bus control Qt
Hi Eugen, I think I got it. MyProgress.cpp: Q_DECLARE_METATYPE(MyProgress) QDBusArgument <<(QDBusArgument , const MyProgress& parameterProgress) { argument.beginStructure(); argument << parameterProgress.m_Progress; argument << parameterProgress.m_Message; argument << parameterProgress.m_Additional; argument.endStructure(); return argument; } const QDBusArgument >>(const QDBusArgument , MyProgress& parameterProgress) { argument.beginStructure(); argument >> parameterProgress.m_Progress; argument >> parameterProgress.m_Message; argument >> parameterProgress.m_Additional; argument.endStructure(); return argument; } MyProgress ::MyProgress(){ qRegisterMetaType(); qDBusRegisterMetaType(); } MyProgress.h: #ifndef MYPROGRESS_H #define MYPROGRESS_H #include #include #include #include class MyProgress { public: MyProgress(); ~MyProgress(); int m_Progress; QString m_Message; int m_Additional; public slots: friend QDBusArgument <<(QDBusArgument , const RaucProgress ); friend const QDBusArgument >>(const QDBusArgument , RaucProgress ); }; #endif // MYPROGRESS_H update.cpp: ... QDBusInterface interface( "de.pengutronix.rauc", "/", "de.pengutronix.rauc.Installer", QDBusConnection::systemBus() ); if (interface.isValid() == true) { qDebug() << "interface is valid"; qDebug() << "Read property (Progress)"; QVariant property = interface.property("Progress"); property.value() >> parameterProgress; qDebug() << parameterProgress.m_Progress; qDebug() << parameterProgress.m_Message; } ... parameterProgress is delcared in the update.h I have a last question. Maybe you can answer it. Why have I add the keyword "friend" in front of the QDBusArguments? I wount compile without it. Many thanks. Kind regards Michael ____________________ Von: RAUC im Auftrag von Stahl, Michael Gesendet: Montag, 2. August 2021 14:45 An: eugen.wi...@jumo.net Cc: RAUC@pengutronix.de Betreff: Re: [RAUC] Antwort: D-Bus control Qt Hi Eugen, thanks for the informations. They were very useful. Some lines are familiar to me because I tested a lot. But I still need some support. This is the way I request the property: MyProgress parameterProgress; QDBusInterface interface( "de.pengutronix.rauc", "/", "de.pengutronix.rauc.Installer", QDBusConnection::systemBus() ); QVariant property = interface.property("Progress"); property.value() >> parameterProgress; No I get a compiler error: no match for operator>>'(opernad types are 'QDBusArgument' and 'MyProgress') I think I do the registration an the installing of the oparators wrong. The registration is done in the constructor of MyProgress: MyProgress ::MyProgress(){ qRegisterMetaType(); qDBusRegisterMetaType(); } The magic statement I place in top of my MyProcess.cpp // this is one of the magic statements Q_DECLARE_METATYPE(MyProgress) But where exactly do you place the operators? Also in the MyProcess.cpp? QDBusArgument <<(QDBusArgument , const MyProgress& parameterProgress); const QDBusArgument >>(const QDBusArgument , MyProgress& parameterProgress); QDBusArgument <<(QDBusArgument , const MyProgress& parameterProgress) { argument.beginStructure(); argument << parameterProgress.m_Progress; argument << parameterProgress.m_Message; argument << parameterProgress.m_Additional; argument.endStructure(); return argument; } const QDBusArgument >>(const QDBusArgument , MyProgress& parameterProgress) { argument.beginStructure(); argument >> parameterProgress.m_Progress; argument >> parameterProgress.m_Message; argument >> parameterProgress.m_Additional; argument.endStructure(); return argument; } It seems like I am only a few millimeters away from my goal. Thanks Von: eugen.wi...@jumo.net Gesendet: Montag, 2. August 2021 13:41 An: Stahl, Michael Cc: RAUC@pengutronix.de Betreff: Antwort: [RAUC] D-Bus control Qt Hi Michael, "RAUC" schrieb am 02.08.2021 08:15:26: > Von: "Stahl, Michael" > An: "RAUC@pengutronix.de" > Datum: 02.08.2021 08:15 > Betreff: [RAUC] D-Bus control Qt > Gesendet von: "RAUC" > > Is there someone who implemented the DBus Property "Progress" into a > Qt-Application? The problem seems the return value isi (Inte
Re: [RAUC] Antwort: D-Bus control Qt
Hi Eugen, thanks for the informations. They were very useful. Some lines are familiar to me because I tested a lot. But I still need some support. This is the way I request the property: MyProgress parameterProgress; QDBusInterface interface( "de.pengutronix.rauc", "/", "de.pengutronix.rauc.Installer", QDBusConnection::systemBus() ); QVariant property = interface.property("Progress"); property.value() >> parameterProgress; No I get a compiler error: no match for operator>>'(opernad types are 'QDBusArgument' and 'MyProgress') I think I do the registration an the installing of the oparators wrong. The registration is done in the constructor of MyProgress: MyProgress ::MyProgress(){ qRegisterMetaType(); qDBusRegisterMetaType(); } The magic statement I place in top of my MyProcess.cpp // this is one of the magic statements Q_DECLARE_METATYPE(MyProgress) But where exactly do you place the operators? Also in the MyProcess.cpp? QDBusArgument <<(QDBusArgument , const MyProgress& parameterProgress); const QDBusArgument >>(const QDBusArgument , MyProgress& parameterProgress); QDBusArgument <<(QDBusArgument , const MyProgress& parameterProgress) { argument.beginStructure(); argument << parameterProgress.m_Progress; argument << parameterProgress.m_Message; argument << parameterProgress.m_Additional; argument.endStructure(); return argument; } const QDBusArgument >>(const QDBusArgument , MyProgress& parameterProgress) { argument.beginStructure(); argument >> parameterProgress.m_Progress; argument >> parameterProgress.m_Message; argument >> parameterProgress.m_Additional; argument.endStructure(); return argument; } It seems like I am only a few millimeters away from my goal. Thanks Von: eugen.wi...@jumo.net Gesendet: Montag, 2. August 2021 13:41 An: Stahl, Michael Cc: RAUC@pengutronix.de Betreff: Antwort: [RAUC] D-Bus control Qt Hi Michael, "RAUC" schrieb am 02.08.2021 08:15:26: > Von: "Stahl, Michael" > An: "RAUC@pengutronix.de" > Datum: 02.08.2021 08:15 > Betreff: [RAUC] D-Bus control Qt > Gesendet von: "RAUC" > > Is there someone who implemented the DBus Property "Progress" into a > Qt-Application? The problem seems the return value isi (Integer, > String, Integer). > For all other properties with a single return value like "Operation" > or "LastError" the Qt DBus API works fine. > I found an email from 28.Oct 2019 in the mailing list where Bastian > Krause had the same issue. The answer was only that he had to > cunsult the Qt DBus documentation on how a tuple is mapped to Qt types. > > Thats a good hint but after hours of searching the web I didn't find > a solution. The return value for a property is QVariant in Qt. > > Trial 1 -> Read value by iface.property("Progress"): > This is the error message I got when I try to read the progress property: > Cannot construct placeholder type QDBusRawType > > Trial 2 -> Read value by iface.call("Get",...): > Not able to get any information. The arguments of the returned > QDBusMessages are always empty! That is the way we implemented it: On Qt there are some pitfalls and you has to marshaling the data. 1. Create a Data Class #include #include #include class MyProgress { public: [...] int m_Progress; QString m_Message; int m_Additional; }; // this is one of the magic statements Q_DECLARE_METATYPE(MyProgress) QDBusArgument <<(QDBusArgument , const MyProgress& parameterProgress); const QDBusArgument >>(const QDBusArgument , MyProgress& parameterProgress); }; You has to register the metatype and implement the operators. In the Constructor you has to add two register Methods qRegisterMetaType(); qDBusRegisterMetaType(); After this tree registrations your Class MyProgress is known by Qt Metatype System. Now you has to implement operators QDBusArgument <<(QDBusArgument , const MyProgress& parameterProgress) { argument.beginStructure(); argument << parameterProgress.m_Progress; argument << parameterProgress.m_Message; argument << parameterProgress.m_Additional; argument.endStructure(); return argument; } const QDBusArgument >>(const QDBusArgument , MyProgress& parameterProgress) { argument.beginStructure(); argument >> parameterProgress.m_Progress; argument >> parameterProgress.m_Message; argument >> parameterProgress.m_Additional; argument.endStructure(); return argument; } Now you are finished with preparing how to use it. In the Qt Slot of the D-Bus call your can pipe it in your class MyProgress parameterProgress; property.value() >> parameterProgress; This URL help you to map our code to the Qt example https://doc.qt.io/qt-5/qdbusargument.html I hope it helps > > ___ > RAUC mailing list Diese E-Mail kann vertrauliche und/oder rechtlich gesch?tzte Informationen