0

I'm trying to get a property value from the dbus. I'm getting no error, but I'm also not getting the right value. In other words, the value returned is not the same value as returned by qdbus. Here is my code:

   const QString service = "org.freedesktop.UPower";
   const QString path = "/org/freedesktop/UPower/devices/line_power_ADP1";
   const QString interface = "org.freedesktop.UPower.Device"; 
   const QString property = "Online";    

   QDBusConnection bus = QDBusConnection::systemBus();

   QList<QVariant> args;
   args.append(QVariant(interface));
   args.append(QVariant(property));

   QDBusMessage mesg = QDBusMessage::createMethodCall(service, path, "org.freedesktop.DBus.Properties", "Get");
   mesg.setArguments(args);   

   QDBusMessage ret = bus.call(mesg);

   if (ret.type() == QDBusMessage::ErrorMessage)
   {
       qDebug() << "Error getting property value.  " << ret.errorName() <<  ":  " << ret.errorMessage();
   }

   bool value = ret.arguments()[0].value<bool>(); //incorrect value!

As far as I can tell, this should get the "Online" property corresponding to the path "/org/freedesktop/UPower/devices/line_power_ADP1" of the service "org.freedesktop.UPower" on the system bus. But in reality, all it's getting is junk -- no error, only junk.

user2602914
  • 301
  • 3
  • 11

1 Answers1

0

Ahhhh ... Well, apparently (just to be confusing lol) the dbus sends information as "QDBusVariant"s. So I need to convert the "QVariant" of the QDBusMessage output to a "QDBusVariant" then back to a "QVariant" and then convert it to the actual value (in this case a "bool"). In other words, I should have used:

bool value = ret.arguments()[0].value<QDBusVariant>().variant().value<bool>(); 

instead of

bool value = ret.arguments()[0].value<bool>(); 
user2602914
  • 301
  • 3
  • 11