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:

Qt Code:
  1. /*** Types.h ***/
  2. // Struct Definition:
  3. struct Position {
  4. int x;
  5. int y;
  6. int angle;
  7. };
To copy to clipboard, switch view to plain text mode 

The Qt Metatype declaration(s) are also made:

Qt Code:
  1. // Qt metatype declaration:
  2. Q_DECLARE_METATYPE(Position)
  3. Q_DECLARE_METATYPE(QList<Position>)
To copy to clipboard, switch view to plain text mode 

The operators << and >> are being overloaded for proper serializing the struct:

Qt Code:
  1. // Marshall the Position data into a D-Bus argument
  2. inline QDBusArgument &operator<<(QDBusArgument &argument, const Position &myPos)
  3. {
  4. argument.beginStructure();
  5. argument << myPos.x << myPos.y << myPos.angle;
  6. argument.endStructure();
  7. return argument;
  8. }
  9.  
  10. // Retrieve the Position data from the D-Bus argument
  11. inline const QDBusArgument &operator>>(const QDBusArgument &argument, Position &myPos)
  12. {
  13. argument.beginStructure();
  14. argument >> myPos.x >> myPos.y >> myPos.angle;
  15. argument.endStructure();
  16. return argument;
  17. }
To copy to clipboard, switch view to plain text mode 

As far as that goes, everything's fine. Now, I've set up an Dbus interface for the transmission:

Qt Code:
  1. /*** Interface.cpp ***/
  2.  
  3. // Declarations in the interface constructor:
  4. qDBusRegisterMetaType<Position>();
  5. qDBusRegisterMetaType<QList<Position> >();
To copy to clipboard, switch view to plain text mode 


Finally, this is my method for the creation of the method call - it's also where the trouble lies in:


Qt Code:
  1. // calling the overloaded operator '<<':
  2. bool Interface::sendPosition(Position pos) {
  3. QDBusMessage message = QDBusMessage::createMethodCall(DEST,PATH,IFACE, "sendPos");
  4. message << pos; // ERROR happens here
  5. return QDBusConnection::sessionBus().send(message);
  6. }
To copy to clipboard, switch view to plain text mode 


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:perator<<(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.