I got it working. Problem was that instead of bool I had to use QVariant of QDBusVariant type. So the two functions look like this now:
These are the defines I've used:
#define BLUEZ_DBUS_SERVICE "org.bluez"
#define BLUEZ_DBUS_PATH "/org/bluez/hci0"
#define BLUEZ_DBUS_IF "org.bluez.Adapter1"
And here is the first implementationÖ
QDBusConnection bus = QDBusConnection::systemBus();
if (!bus.isConnected())
{
qFatal("Cannot connect to the D-Bus session bus.");
return;
}
QDBusMessage message = QDBusMessage::createMethodCall(BLUEZ_DBUS_SERVICE,
BLUEZ_DBUS_PATH,
"org.freedesktop.DBus.Properties",
"Set");
QList<QVariant> arguments;
arguments << BLUEZ_DBUS_IF
<< "Powered"
<< QVariant::fromValue(QDBusVariant(true));
message.setArguments(arguments);
QDBusPendingReply<QVariantMap> reply = bus.asyncCall(message);
reply.waitForFinished();
and here is the second possibility to implement the method call:
QDBusConnection bus = QDBusConnection::systemBus();
if (!bus.isConnected())
{
qFatal("Cannot connect to the D-Bus session bus.");
return;
}
QDBusInterface dbus_iface(BLUEZ_DBUS_SERVICE,
BLUEZ_DBUS_PATH,
"org.freedesktop.DBus.Properties",
bus);
if ( dbus_iface.isValid() ) {
QDBusPendingReply<QVariantMap> reply = dbus_iface.asyncCall("Set",
BLUEZ_DBUS_IF,
"Powered",
QVariant::fromValue(QDBusVariant(true)));
reply.waitForFinished();
reply.error().message();
}
In case anybody wants to do the same thing there is also the possibility to set the "Powered" property directly:
QDBusInterface ifc(
BLUEZ_DBUS_SERVICE,
BLUEZ_DBUS_PATH,
BLUEZ_DBUS_IF,
QDBusConnection::systemBus());
if ( ifc.isValid() ) {
ifc.setProperty("Powered", true);
}