Hi Michael,

"RAUC" <rauc-boun...@pengutronix.de> schrieb am 02.08.2021 08:15:26:

> Von: "Stahl, Michael" <mst...@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-boun...@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 
_______________________________________________
RAUC mailing list

Reply via email to