mail archive of the rauc mailing list
 help / color / mirror / Atom feed
From: "Stahl, Michael" <mstahl@moba.de>
To: "Eugen.Wiens@JUMO.net" <Eugen.Wiens@JUMO.net>
Cc: "RAUC@pengutronix.de" <RAUC@pengutronix.de>
Subject: Re: [RAUC] Antwort:  D-Bus control Qt
Date: Mon, 2 Aug 2021 13:20:25 +0000	[thread overview]
Message-ID: <AM9PR09MB4756411B8C78CCE0C6E9E898DBEF9@AM9PR09MB4756.eurprd09.prod.outlook.com> (raw)
In-Reply-To: <AM9PR09MB47563BB4F309DDD51814BF72DBEF9@AM9PR09MB4756.eurprd09.prod.outlook.com>


[-- Attachment #1.1: Type: text/plain, Size: 9070 bytes --]

Hi Eugen,

I think I got it.

MyProgress.cpp:
Q_DECLARE_METATYPE(MyProgress)


QDBusArgument &operator<<(QDBusArgument &argument, const MyProgress& parameterProgress)

{

    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<MyProgress>();

    qDBusRegisterMetaType<MyProgress>();

}


MyProgress.h:

#ifndef MYPROGRESS_H


#define MYPROGRESS_H

#include <QObject>

#include <QDBusArgument>

#include <QMetaType>

#include <QDBusMetaType>


class MyProgress

{

public:

    MyProgress();

    ~MyProgress();

    int m_Progress;

    QString m_Message;

    int m_Additional;

public slots:

    friend QDBusArgument &operator<<(QDBusArgument &argument, const RaucProgress &parameterProgress);

    friend const QDBusArgument &operator>>(const QDBusArgument &argument, RaucProgress &parameterProgress);

};

#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<QDBusArgument>() >> 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 <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;
QDBusInterface interface( "de.pengutronix.rauc",

                    "/",

                    "de.pengutronix.rauc.Installer",

                    QDBusConnection::systemBus() );

QVariant property = interface.property("Progress");

property.value<QDBusArgument>() >> 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<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?
QDBusArgument &operator<<(QDBusArgument &argument, const MyProgress& parameterProgress);
const QDBusArgument &operator>>(const QDBusArgument &argument, MyProgress& parameterProgress);
QDBusArgument &operator<<(QDBusArgument &argument, const MyProgress& parameterProgress)
{
    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 <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> schrieb am 02.08.2021 08:15:26:

> Von: "Stahl, Michael" <mstahl@moba.de>
> An: "RAUC@pengutronix.de" <RAUC@pengutronix.de>
> Datum: 02.08.2021 08:15
> Betreff: [RAUC] D-Bus control Qt
> Gesendet von: "RAUC" <rauc-bounces@pengutronix.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 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 <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 QDBusArgument &argument, MyProgress& parameterProgress);
};

You has to register the metatype and implement the operators. 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_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<QDBusArgument>() >> 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 bestimmt. Das unerlaubte Kopieren sowie die unbefugte Weitergabe dieser Mail sind nicht gestattet. Bitte benachrichtigen Sie uns gegebenenfalls telefonisch 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?glich. Falls nicht ausdr?cklich vermerkt, ist diese E-Mail keine rechtlich bindende Vereinbarung.

Kommanditgesellschaft: JUMO GmbH & Co. KG, Sitz: 36039 Fulda, Amtsgericht 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

[-- Attachment #1.2: Type: text/html, Size: 48045 bytes --]

[-- Attachment #2: Type: text/plain, Size: 66 bytes --]

_______________________________________________
RAUC mailing list

  reply	other threads:[~2021-08-02 13:20 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-02  6:15 [RAUC] " Stahl, Michael
2021-08-02  8:14 ` Bastian Krause
2021-08-02  8:53   ` Wolk, Steffen
2021-08-02 11:41 ` [RAUC] Antwort: " Eugen.Wiens
2021-08-02 12:45   ` Stahl, Michael
2021-08-02 13:20     ` Stahl, Michael [this message]
2021-08-02 13:36       ` [RAUC] Antwort: " Eugen.Wiens
2021-08-02 14:29         ` Stahl, Michael
2021-08-02 14:53           ` [RAUC] Antwort: " Eugen.Wiens
2021-08-03  6:21             ` Stahl, Michael
2021-08-03  6:27               ` [RAUC] Antwort: " Eugen.Wiens
2021-08-03  8:27                 ` Stahl, Michael
2021-08-03 10:57                   ` Stahl, Michael
2021-08-03 11:00                   ` Stahl, Michael
2021-08-03 11:14                     ` [RAUC] Antwort: " Eugen.Wiens
2021-08-03 13:27                       ` Stahl, Michael

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=AM9PR09MB4756411B8C78CCE0C6E9E898DBEF9@AM9PR09MB4756.eurprd09.prod.outlook.com \
    --to=mstahl@moba.de \
    --cc=Eugen.Wiens@JUMO.net \
    --cc=RAUC@pengutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox