Results 1 to 4 of 4

Thread: Problems with marshalling a struct to Qt/DBus

  1. #1
    Join Date
    Dec 2009
    Posts
    1
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default 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:

    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.

  2. #2
    Join Date
    Apr 2010
    Posts
    2
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default 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?

  3. #3
    Join Date
    Apr 2010
    Posts
    2
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default 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.

  4. #4
    Join Date
    Jan 2014
    Posts
    1
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default 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 :
    Qt Code:
    1. // calling the overloaded operator '<<':
    2. bool Interface::sendPosition(Position pos) {
    3. QDBusMessage message = QDBusMessage::createMethodCall(DEST,PATH,IFACE, "sendPos");
    4. message << QVariant::fromValue(pos);
    5. return QDBusConnection::sessionBus().send(message);
    6. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Problems with scope and C header functions
    By waldowoc in forum Newbie
    Replies: 5
    Last Post: 5th August 2008, 11:29
  2. Replies: 16
    Last Post: 23rd May 2008, 10:12
  3. Make error with Qt Jambi 4.3.2_01
    By pamalite in forum Installation and Deployment
    Replies: 0
    Last Post: 22nd November 2007, 12:05

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.