From mboxrd@z Thu Jan 1 00:00:00 1970 Return-path: Received: from mail-he1eur01on0612.outbound.protection.outlook.com ([2a01:111:f400:fe1e::612] helo=EUR01-HE1-obe.outbound.protection.outlook.com) by metis.ext.pengutronix.de with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mAXro-0004w9-U3 for RAUC@pengutronix.de; Mon, 02 Aug 2021 15:20:30 +0200 From: "Stahl, Michael" Date: Mon, 2 Aug 2021 13:20:25 +0000 Message-ID: References: , , In-Reply-To: Content-Language: de-DE MIME-Version: 1.0 Subject: Re: [RAUC] Antwort: D-Bus control Qt List-Id: RAUC Project - Discussion List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: multipart/mixed; boundary="===============1148977578==" Errors-To: rauc-bounces@pengutronix.de Sender: "RAUC" To: "Eugen.Wiens@JUMO.net" Cc: "RAUC@pengutronix.de" --===============1148977578== Content-Language: de-DE Content-Type: multipart/alternative; boundary="_000_AM9PR09MB4756411B8C78CCE0C6E9E898DBEF9AM9PR09MB4756eurp_" --_000_AM9PR09MB4756411B8C78CCE0C6E9E898DBEF9AM9PR09MB4756eurp_ Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Hi Eugen, I think I got it. MyProgress.cpp: Q_DECLARE_METATYPE(MyProgress) QDBusArgument &operator<<(QDBusArgument &argument, const MyProgress& parame= terProgress) { argument.beginStructure(); argument << parameterProgress.m_Progress; argument << parameterProgress.m_Message; argument << parameterProgress.m_Additional; argument.endStructure(); return argument; } const QDBusArgument &operator>>(const QDBusArgument &argument, 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 &operator<<(QDBusArgument &argument, const RaucPro= gress ¶meterProgress); friend const QDBusArgument &operator>>(const QDBusArgument &argument, R= aucProgress ¶meterProgress); }; #endif // MYPROGRESS_H update.cpp: ... QDBusInterface interface( "de.pengutronix.rauc", "/", "de.pengutronix.rauc.Installer", QDBusConnection::systemBus() ); if (interface.isValid() =3D=3D true) { qDebug() << "interface is valid"; qDebug() << "Read property (Progress)"; QVariant property =3D 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.Wiens@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 =3D 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 &operator<<(QDBusArgument &argument, const MyProgress& parame= terProgress); const QDBusArgument &operator>>(const QDBusArgument &argument, MyProgress& = parameterProgress); QDBusArgument &operator<<(QDBusArgument &argument, const MyProgress& parame= terProgress) { argument.beginStructure(); argument << parameterProgress.m_Progress; argument << parameterProgress.m_Message; argument << parameterProgress.m_Additional; argument.endStructure(); return argument; } const QDBusArgument &operator>>(const QDBusArgument &argument, 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.Wiens@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 &operator<<(QDBusArgument &argument, const MyProgress& parame= terProgress); const QDBusArgument &operator>>(const QDBusArgument &argument, MyProgress& = parameterProgress); }; You has to register the metatype and implement the operators. In the Constr= uctor 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 &operator<<(QDBusArgument &argument, const MyProgress& parame= terProgress) { argument.beginStructure(); argument << parameterProgress.m_Progress; argument << parameterProgress.m_Message; argument << parameterProgress.m_Additional; argument.endStructure(); return argument; } const QDBusArgument &operator>>(const QDBusArgument &argument, 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 = beinhalten und ist ausschlie?lich f?r die im Verteiler genannten Personen b= estimmt. Das unerlaubte Kopieren sowie die unbefugte Weitergabe dieser Mail= sind nicht gestattet. Bitte benachrichtigen Sie uns gegebenenfalls telefon= isch oder mit Antwort-Mail, falls Sie nicht der richtige Adressat dieser E-= Mail sind. Bitte l?schen Sie diese Nachricht und alle Anh?nge dazu unverz?g= lich. Falls nicht ausdr?cklich vermerkt, ist diese E-Mail keine rechtlich b= indende Vereinbarung. Kommanditgesellschaft: JUMO GmbH & Co. KG, Sitz: 36039 Fulda, Amtsgericht F= ulda HRA 302, Pers?nlich haftende Gesellschafterin: M. K. JUCHHEIM GmbH, Si= tz: 36039 Fulda, Amtsgericht Fulda HRB 17, Gesch?ftsf?hrer: Dipl.-Ing. Bern= hard Juchheim, Dipl.-Kfm. Michael Juchheim, Dipl.-Ing. Dimitrios Charisiadi= s Ust.-Id.-Nr.: DE 112411234 --_000_AM9PR09MB4756411B8C78CCE0C6E9E898DBEF9AM9PR09MB4756eurp_ Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
Hi Eugen,

I think I got it.

MyProgress.cpp:
Q_DECLARE_METATYPE(MyProgress)

QDBusArgument &operator<=
;<(QDBusArgument &=
amp;argument, <=
span style=3D"font-family: Calibri, Arial, Helvetica, sans-serif; font-size=
: 12pt; color: rgb(128, 128, 0);">const MyProgress& parameterProgress<=
span style=3D"color: rgb(0, 0, 0); font-family: Calibri, Arial, Helvetica, =
sans-serif; font-size: 12pt;">)
{
    argument.beginStructure();
    argument << parameterProgress.m_Progress;
    argument << parameterProgress.m_Message;
    argument << parameterProgress.m_Additional;
    argument.endStructure();
    return argument=
;
}

const QDBusArgument &operator>&g=
t;(const=
 QDBusArgument &argument=
, MyProgress& parameterProgress)
{
    argument.beginStructure();
    argument >> parameterProgress.m_Progress;
    argument >> parameterProgress.m_Message;
    argument >> parameterProgress.m_Additional;
    argument.endStructure();
    return argument=
;
}


MyProgress ::MyProgress(){
    qRegisterMetaType<MyProgress>();
    qDBusRegisterMetaTy=
pe<MyProgress>();
}

MyProgress.h:
#ifndef MYPROGRESS_H=
=0A=
#define MYPROGRESS_H
=0A=
#include <QObject>
#include <QDBusArgument>
#include <QMetaType>
#include <QDBusMetaType>

class MyProgress
{
public:
    MyProgress=
();
    ~MyProgress<=
/span>();
    int m_Progress;
=
    QString m_Message;
    int <=
span style=3D"color:#800000">m_Additional;
public slots<=
/span>:
    friend QDBusArgument &operator<<(QDBusArgument&nbs=
p;&argument, const RaucProgress &parameterProgress);
    friend =
;const QDBusArgument &operator>>(const QDBusArgument &argume=
nt, RaucProgress &paramet=
erProgress);
};
<= pre style=3D"margin-top:0px;margin-bottom:0px">#endif //&nb= sp;MYPROGRESS_H

update.cpp:
...
&nb=
sp;   QDBusInterfaceinterface( "de.pengutronix.rauc",=0A=
                  =
            "/",
          &nbs=
p;                   "de.pengutronix.rauc.Installer",
                 =
             QDBusConnection::systemBus=
() );

    if (interface.i=
sValid() =3D=3D true)<=
/pre>
    {
        qDebug() << "interface&=
nbsp;is valid";
<= pre style=3D"color: rgb(0, 0, 0); font-family: Calibri, Arial, Helvetica, s= ans-serif; margin-top: 0px; margin-bottom: 0px;"> qDebug= () << "Read property (Progress)";
       QVariant property =3D interface.property("Progress");
    =
  property.value=
<>() >=
;> parameterProgress
<= /pre>
       qDebug() << parameterProgress.<=
span style=3D"font-family: Calibri, Arial, Helvetica, sans-serif; font-size=
: 12pt; color: rgb(128, 0, 0);">m_Progress;
       qDebug() <&=
lt; 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 QDBusArgu=
ments? I wount compile without it.

Many thanks.

Kind regards 
Michael





Von: RAUC <rauc-bounces@= pengutronix.de> im Auftrag von Stahl, Michael <mstahl@moba.de>
Gesendet: Montag, 2. August 2021 14:45
An: Eugen.Wiens@JUMO.net <Eugen.Wiens@JUMO.net>
Cc: RAUC@pengutronix.de <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;
QDBusInt= erface interface( "de.pengutronix.rauc",
                    <=
/span>"/",
                    "de.pengutronix.rauc.Installer",
                    <=
/span>QDBusConnection::systemBus() );
QVariant= property =3D interface.property("Progress");
p=
roperty.value=
<QDBusArgu=
ment>()&=
nbsp;>>parameterProgress;

=
No I=
 get a compiler error:
no m=
atch for operator>>'(opernad types are 'QDBusArgument' and 'MyProgres=
s')

=
I th=
ink I do the registration an the installing of the oparators wrong.<=
/pre>

=
The =
registration is done in the constructor of MyProgress:
=
MyProgress ::=
My<=
span style=3D"font-family:calibri,arial,helvetica,sans-serif; font-size:12p=
t; color:rgb(0,103,124); background-color:rgba(0,0,0,0)">Progress()=
{
=
    qRegisterMetaType=
<MyProgress>();
    qDBusRegisterMetaType<MyProgress>();
}

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?&nb= sp;
QDBusArgument &operator<<(QDBusArgument &argument, con= st MyProgress& parameterProgress);
const QDBusArgument &operator>>(const QDBusArgument &a= rgument, MyProgress& parameterProgress);
QDBusArgument &operator<<(QDBusArgument &argument, con= st MyProgress& parameterProgress)
{
    argument.beginStructure();
    argument << parameterProgress.m_Progress;=
    argument << parameterProgress.m_Message;<= /tt>
    argument << parameterProgress.m_Additional;
    argument.endStructure();
    return argument;
}
const QDBusArgument &operator>>(const QDBusArgument &a= rgument, MyProgress& parameterProgress)
{
    argument.beginStructure();
    argument >> parameterProgress.m_Progress;=
    argument >> parameterProgress.m_Message;<= /tt>
    argument >> parameterProgress.m_Additional;
    argument.endStructure();
    return argument;
}

It seems like I am only a few millimeters away from my goal.

Thanks


Von: Eugen.Wiens@JUMO.net= <Eugen.Wiens@JUMO.net>
Gesendet: Montag, 2. August 2021 13:41
An: Stahl, Michael <mstahl@moba.de>
Cc: RAUC@pengutronix.de <RAUC@pengutronix.de>
Betreff: Antwort: [RAUC] D-Bus control Qt
 
Hi Michael,

"RAUC" <rauc-bounces@pengutronix.de> s= chrieb am 02.08.2021 08:15:26:

> Von: "Stahl, Michael" <mstahl@moba.de>

> An: "RAUC@pengutronix.de" <RAUC@peng= utronix.de>
> Datum: 02.08.2021 08:15
> Betreff: [RAUC] D-Bus control Qt
> Gesendet von: "RAUC" <rauc-bounces@p= engutronix.de>
>
> 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 val= ue 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 rea= d 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 marshalin= g the data.

1. Create a Data Class

#include <QObject>
#include <QDBusArgument>
#include <QString>

class MyProgress
{
public:
[...]
    int m_Progress;
    QString m_Message;
    int m_Additional;
};

// this is one of the magic statements Q_DECLARE_METATYPE(MyProgress)
QDBusArgument &operator<<(QDBusArgument &= ;argument, const MyProgress& parameterProgress);
const QDBusArgument &operator>>(const QDBusA= rgument &argument, MyProgress& parameterProgress);
};

You has to register the metatype and implement the ope= rators. In the Constructor you has to add two register Methods

qRegisterMetaType<MyProgress>();
qDBusRegisterMetaType<MyProgress>();=

After this tree registrations your Class MyProgress is= known by Qt Metatype System. Now you has to implement operators

QDBusArgument &operator<<(QDBusArgument &= ;argument, const MyProgress& parameterProgress)
{
    argument.beginStructure();     argument << parameterProgress.m_Pr= ogress;
    argument << parameterProgress.m_Me= ssage;
    argument << parameterProgress.m_Ad= ditional;
    argument.endStructure();
    return argument;
}
const QDBusArgument &operator>>(const QDBusA= rgument &argument, MyProgress& parameterProgress)
{
    argument.beginStructure();     argument >> parameterProgress.m_Pr= ogress;
    argument >> parameterProgress.m_Me= ssage;
    argument >> parameterProgress.m_Ad= ditional;
    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<QDBusArgument>() >> paramet= erProgress;


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 In= formationen beinhalten und ist ausschlie?lich f?r die im Verteiler genannte= n Personen bestimmt. Das unerlaubte Kopieren sowie die unbefugte Weitergabe dieser Mail sind nicht gestattet. Bitte ben= achrichtigen Sie uns gegebenenfalls telefonisch oder mit Antwort-Mail, fall= s Sie nicht der richtige Adressat dieser E-Mail sind. Bitte l?schen Sie die= se Nachricht und alle Anh?nge dazu unverz?glich. Falls nicht ausdr?cklich vermerkt, ist diese E-Mail keine re= chtlich bindende Vereinbarung.

Kommanditgesellschaft: JUMO GmbH & Co. KG, Sitz: 36039 Fulda, Amtsgeric= ht Fulda HRA 302, Pers?nlich haftende Gesellschafterin: M. K. JUCHHEIM GmbH= , Sitz: 36039 Fulda, Amtsgericht Fulda HRB 17, Gesch?ftsf?hrer: Dipl.-Ing. = Bernhard Juchheim, Dipl.-Kfm. Michael Juchheim, Dipl.-Ing. Dimitrios Charisiadis
Ust.-Id.-Nr.: DE 112411234

--_000_AM9PR09MB4756411B8C78CCE0C6E9E898DBEF9AM9PR09MB4756eurp_-- --===============1148977578== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ RAUC mailing list --===============1148977578==--