How to transfer QPolygonF via DBus

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


    then in a function:


    also, 2 adequate operators:

    const QDBusArgument &operator>>(const QDBusArgument &argument, QPolygonF& pol)
        while ( !argument.atEnd() ) {
            QPointF qp;
            argument >> qp;
        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));
     return argument;

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

    What's wrong ?

  • 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

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

  • Noticed the following behavior:

    QPolygonF pol;
    QDBusVariant dbv;
    QVariant v, v1;
    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 ?

  • Lifetime Qt Champion


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

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

  • Lifetime Qt Champion

    You can't, why not juste:

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


  • 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 :-(

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

    #include <QPolygonF>
    class Foo
     Q_CLASSINFO("D-Bus Interface", "")
     void MyMethod(int i, const QPolgonF& p);

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

Log in to reply