qdbus - can't connect to dbus signal with struct argument

1.1k views Asked by At

I'm trying to connect to amarok d-bus signal StatusChange (reference: https://xmms2.org/wiki/MPRIS#StatusChange). Interface and struct is ok because I can connect to simple signal CapsChange(int) in same interface and can get status by GetStatus dbus method, so this marshall struct is ok:

struct AmarokStatus {
    int st1;
    int st2;
    int st3;
    int st4;
};

Q_DECLARE_METATYPE(AmarokStatus)
qDBusRegisterMetaType<AmarokStatus>();

But when call:

mInf = new QDBusInterface("org.mpris.MediaPlayer2.amarok", "/Player",
                          "org.freedesktop.MediaPlayer", QDBusConnection::sessionBus(),this);
connect(mInf, SIGNAL(StatusChange(AmarokStatus)), this, SLOT(statusChanged(AmarokStatus)));
connect(mInf, SIGNAL(CapsChange(int)), this, SLOT(capsChange(int)));

I got message:

Object::connect: No such signal org::freedesktop::MediaPlayer::StatusChange(AmarokStatus)

I have tried with SIGNAL(StatusChange(struct)) and SIGNAL(StatusChange(QDbusargument)) and other types but same message

D-Feet is saying that definition of StatusChange is: StatusChange(Struct of (Int32, Int32, Int32, Int32)), same with dbus-monitor. And same problem with signal TrackChange(array of struct). So I'm definitely messing something with connect() method.

1

There are 1 answers

0
Logan On

There are two options:

  1. Ensure the emitter which implements QDBusAbstractInterface defines the signal you are connecting to. This solution is a bit cleaner.

or

  1. Use QDBusConnection::connect to connect to an anonymous signal. This solution works in a pinch but in my experience can be particularly error-prone:
if (!QDBusConnection::systemBus().connect("org.mpris.MediaPlayer2.amarok", "/Player", "org.freedesktop.MediaPlayer", "StatusChange", this, SLOT(statusChanged(AmarokStatus)))) {
    qWarning() << "Failed to connect";
}