Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to transfer QPolygonF via DBus

How to transfer QPolygonF via DBus

Scheduled Pinned Locked Moved General and Desktop
9 Posts 2 Posters 2.7k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    skylendar
    wrote on last edited by skylendar
    #1

    Hi there and thx for reading and answering if you can.

    I'm on a linux box x86_64 with Qt5.4 downloaded from the qt site, and I need to transfer a QPolygonF to another process via DBus.

    In order to do that, I wrote:

    Q_DECLARE_METATYPE(QPolygonF)

    then in a function:

    qDBusRegisterMetaType<QPolygonF>();

    also, 2 adequate operators:

    const QDBusArgument &operator>>(const QDBusArgument &argument, QPolygonF& pol)
    {
        argument.beginArray();
        pol.clear();
    
        while ( !argument.atEnd() ) {
            QPointF qp;
            argument >> qp;
            pol.append(qp);
        }
    
        argument.endArray();
        return argument;
    }
    
    const QDBusArgument &operator<<(QDBusArgument &argument, const QPolygonF& pol)
    {
    	argument.beginArray();	for(QPolygonF::const_iterator it = pol.begin(); it != pol.end(); ++it)
    			argument << static_cast<QPointF>(*it));
        argument.endArray();
     return argument;
    }
    

    So far, gcc accepts these declarations, but when I run my app, it crashes.

    What's wrong ?

    1 Reply Last reply
    0
    • S Offline
      S Offline
      skylendar
      wrote on last edited by
      #2

      Ah, and I forgot to say that I got this output from the crashed app:

      QDBusArgument: read from a write-only object
      process 9243: arguments to dbus_message_unref() were incorrect, assertion "message->generation == _dbus_current_generation" failed in file dbus-message.c line 1695.
      This is normally a bug in some application using the D-Bus library.
        D-Bus not built with -rdynamic so unable to print a backtrace
      
      1 Reply Last reply
      0
      • S Offline
        S Offline
        skylendar
        wrote on last edited by
        #3

        Do I also need to declare all the shebang for QPointF ?

        1 Reply Last reply
        0
        • S Offline
          S Offline
          skylendar
          wrote on last edited by skylendar
          #4

          Noticed the following behavior:

          QPolygonF pol;
          QDBusVariant dbv;
          QVariant v, v1;
          v.setValue<QPolygonF>(pol);
          dbv.setVariant(v);
          QVariant v1 = QVariant::fromValue(dbv);
          qDebug() << "typename" << v.typeName() << v1.typeName();
          

          QPolygonF QDBusVariant

          As you can see, there is a discrepancy between both QVariants. Is this a bug ?

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            Hi,

            AFAIK, no, you are effectively putting a QDBusVariant containing a QPolygonF in a QVariant. So at first level, what you see it correct.

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0
            • S Offline
              S Offline
              skylendar
              wrote on last edited by
              #6

              Thx for answering.

              But I still need to transfer a QPolygonF via QDBusVariant. If I do as above, dbv contains a DBusVariant, not the corresponding QVariant.

              How to initialize dbv so that QVariant::fromValue() returns a QVariant containing a QPolygonF, and not its QDBusVariant ?

              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #7

                You can't, why not juste:

                     QDBusVariant dbusVariant = qvariant_cast<QDBusVariant>(v1);
                     QPolygonF result = qvariant_cast<QPolygonF>(dbusVariant.variant());
                

                ?

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                S 1 Reply Last reply
                0
                • SGaistS SGaist

                  You can't, why not juste:

                       QDBusVariant dbusVariant = qvariant_cast<QDBusVariant>(v1);
                       QPolygonF result = qvariant_cast<QPolygonF>(dbusVariant.variant());
                  

                  ?

                  S Offline
                  S Offline
                  skylendar
                  wrote on last edited by skylendar
                  #8

                  Thanks again for proposing a solution, but it doesn't work. I even got:

                  QDBusMarshaller: cannot add a null QDBusVariant
                  

                  as a log message when running my stuff.

                  when qdbusxml2cpp produces the corresponding dbus glue method, the body of this method relies on QVariant::fromValue(myQDBusVariant) for creating its argumentList, but instead of returning the QVariant containing a QPolygonF, fromValue returns a QVariant containing a QDbusVariant containing the QpolygonF.

                  Arghhh :-(

                  1 Reply Last reply
                  0
                  • S Offline
                    S Offline
                    skylendar
                    wrote on last edited by skylendar
                    #9

                    OK, found the error !!! My method used QDBusvariant instead of const QPolygonF. But the solution of one problem yields the opening of a new one:

                    in my header parsed by qdbuscpp2xml in my CMakeList, my method is completely ignored; the corresponding xml file doesn't include any entry relative to it. Example:

                    foo.h
                    
                    #include <QPolygonF>
                    Q_DECLARE_METATYPE(QPolygonF)
                    
                    class Foo
                    {
                     Q_OBJECT
                     Q_CLASSINFO("D-Bus Interface", "mysoft.foo")
                    public:
                    
                     void MyMethod(int i, const QPolgonF& p);
                    };
                    

                    MyMethod is ignored. qdbuscpp2xml returns: Type not registered with QtDBus in parameter list: QPolygonF

                    1 Reply Last reply
                    0

                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved