Problems with marshalling a struct to Qt/DBus
Hi people,
I'm (fairly) new to C++/Qt/DBus and stuck with a problem I need to solve ASAP. I've also read the provided tutorials from the Qt Assistant and tried to look up on the internet for a solution, however no help as of now. I strongly hope anyone of you guys can help me out.
Let's get straight to the point:
I'm trying to send this simple struct over DBus:
Code:
/*** Types.h ***/
// Struct Definition:
struct Position {
int x;
int y;
int angle;
};
The Qt Metatype declaration(s) are also made:
Code:
// Qt metatype declaration:
Q_DECLARE_METATYPE(Position)
Q_DECLARE_METATYPE(QList<Position>)
The operators << and >> are being overloaded for proper serializing the struct:
Code:
// Marshall the Position data into a D-Bus argument
{
argument.beginStructure();
argument << myPos.x << myPos.y << myPos.angle;
argument.endStructure();
return argument;
}
// Retrieve the Position data from the D-Bus argument
{
argument.beginStructure();
argument >> myPos.x >> myPos.y >> myPos.angle;
argument.endStructure();
return argument;
}
As far as that goes, everything's fine. Now, I've set up an Dbus interface for the transmission:
Code:
/*** Interface.cpp ***/
// Declarations in the interface constructor:
qDBusRegisterMetaType<Position>();
qDBusRegisterMetaType<QList<Position> >();
Finally, this is my method for the creation of the method call - it's also where the trouble lies in:
Code:
// calling the overloaded operator '<<':
bool Interface::sendPosition(Position pos) {
message << pos; // ERROR happens here
}
The error occurrs when trying to compile the code - it's something around the usage of the overloaded << operator. This is the error message I get:
src/Interface.cpp: In member function ‘bool Interface::sendPosition(QString, Position)’:
src/Interface.cpp:179: error: no match for ‘operator<<’ in ‘message << pos’
/usr/include/qt4/QtDBus/qdbusmessage.h:109: note: candidates are: QDBusMessage& QDBusMessage::operator<<(const QVariant&)
/usr/include/qt4/QtCore/qchar.h:389: note: QDataStream& operator<<(QDataStream&, const QChar&)
[...]
//plenty of candidates listed, but none is matching...
[...]
src/Types.h:27: note: QDBusArgument& operator<<(QDBusArgument&, const Position&)
OS is Ubuntu Linux 9.04, Qt Version 4.5.0 (installed with the 'Synaptic Package Manager').
Any help is highly appreciated!
Thanks + Cheers,
Sascha.
Re: Problems with marshalling a struct to Qt/DBus
Hi,
I'm trying to do quite about exactly the same thing you have tried. I get the code to compile, but for some reason the method that takes the struct as a parameter, does not show up in the method listing I get with qdbus.
Have you managed to get this working yet? Anyone have any ideas what might be wrong?
Re: Problems with marshalling a struct to Qt/DBus
Hi again,
I noticed that (at least if i understand your post correctly) you seem to have the stream operators in the header file. For me this didn't work. To get it working, I added the signatures of the methods to the header file and the implementation to a separate source file. This way it does compile, but as stated before, does not show up in the method list.
Re: Problems with marshalling a struct to Qt/DBus
Check the signature http://qt-project.org/doc/qt-4.8/qdbusmessage.html#operator-lt-lt
The simplest solution :
Code:
// calling the overloaded operator '<<':
bool Interface::sendPosition(Position pos) {
}