How do I extract the returned data from QDBusMessage in a Qt DBus call?

后端 未结 2 2000
伪装坚强ぢ
伪装坚强ぢ 2021-01-01 02:09

I\'m trying to call WPA supplicant\'s DBus interface using Qt\'s QDBus class library. In particular, I\'m trying to use the \"Get\" property call to retrieve the \"Interface

2条回答
  •  [愿得一人]
    2021-01-01 02:45

    My goal was to get the object path returned by GetInterface method of fi.w1.wpa_supplicant1 interface.

    @MatthewD's answer was really helpful to get me started with the experiment but unfortunately didnt work for me as required. I tried all posibilities. But at the end, somehow, I got my required result in a different and a rather shorter way.

    What I did was:
    - I had the interface:
    QDBusInterface interface("fi.w1.wpa_supplicant1", "/fi/w1/wpa_supplicant1", "fi.w1.wpa_supplicant1", QDBusConnection::systemBus());

    - Call the method and store message
    QDBusMessage mesg = interface.call("GetInterface", "wlan0");

    - Then get the first argument
    QVariant var = mesg.arguments().at(0);

    - Then get the object path
    QDBusObjectPath objpath = var.value();

    - And finally
    QString path_str = objpath.path();

    Now you print the path as string:
    printf("Object path: %s\n", path_str);

提交回复
热议问题