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:
/*** Types.h ***/
// Struct Definition:
struct Position {
int x;
int y;
int angle;
};
/*** Types.h ***/
// Struct Definition:
struct Position {
int x;
int y;
int angle;
};
To copy to clipboard, switch view to plain text mode
The Qt Metatype declaration(s) are also made:
// Qt metatype declaration:
Q_DECLARE_METATYPE(Position)
Q_DECLARE_METATYPE(QList<Position>)
// Qt metatype declaration:
Q_DECLARE_METATYPE(Position)
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:
// 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;
}
// Marshall the Position data into a D-Bus argument
inline QDBusArgument &operator<<(QDBusArgument &argument, const Position &myPos)
{
argument.beginStructure();
argument << myPos.x << myPos.y << myPos.angle;
argument.endStructure();
return argument;
}
// Retrieve the Position data from the D-Bus argument
inline const QDBusArgument &operator>>(const QDBusArgument &argument, Position &myPos)
{
argument.beginStructure();
argument >> myPos.x >> myPos.y >> myPos.angle;
argument.endStructure();
return argument;
}
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:
/*** Interface.cpp ***/
// Declarations in the interface constructor:
qDBusRegisterMetaType<Position>();
qDBusRegisterMetaType<QList<Position> >();
/*** Interface.cpp ***/
// Declarations in the interface constructor:
qDBusRegisterMetaType<Position>();
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:
// calling the overloaded operator '<<':
bool Interface::sendPosition(Position pos) {
message << pos; // ERROR happens here
}
// calling the overloaded operator '<<':
bool Interface::sendPosition(Position pos) {
QDBusMessage message = QDBusMessage::createMethodCall(DEST,PATH,IFACE, "sendPos");
message << pos; // ERROR happens here
return QDBusConnection::sessionBus().send(message);
}
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.
Bookmarks