I'm having a problem with qdbus. I need to pass sba(sv) to the SetUnitProperties method. I am only able to pass sba{sv} by using a dictonary. I can't find any documentation or examples on how to pass an array. Here is the error message : "Invalid arguments 'sba{sv}' to call org.freedesktop.systemd1.Manager.SetUnitProperties(), expecting 'sba(sv)'.".
I have also tried using StartTransienUnit which is even more complicated requiring ssa(sv)a(sa(sv)) !
Here is my code in C:
int QUsbDeviceWrapper::swUpdate() {
// Initialize the D-Bus connection
QDBusConnection connection = QDBusConnection::systemBus();
// Check if the connection is valid
if (!connection.isConnected()) {
qWarning("Cannot connect to the D-Bus system bus");
return 1;
}
// Obtain a proxy object for the systemd1 service
QDBusInterface managerInterface("org.freedesktop.systemd1",
"/org/freedesktop/systemd1",
"org.freedesktop.systemd1.Manager",
connection);
// Check if the interface is valid
if (!managerInterface.isValid()) {
qWarning("Failed to obtain interface to systemd1.Manager");
return 1;
}
// Prepare arguments for the SetUnitProperties method
QString serviceName = "[email protected]";
bool runtime = true;
QVariantMap properties;
properties.insert("StopWhenUnneeded", QVariant(false)); // Use QVariant for boolean value
// Call the SetUnitProperties method
QDBusMessage response = managerInterface.call("SetUnitProperties", serviceName, runtime, properties);
// Check if the call was successful
if (response.type() == QDBusMessage::ErrorMessage) {
qWarning() << "Error calling SetUnitProperties:" << response.errorMessage();
return 1;
}
qDebug() << "SetUnitProperties call successful";
return 0;
}
I have tried using a QVariantMap to define the array but dbus doesen't accept it. I was expecting dbus to change the unit's properties.