- QDBusInterface* dbusIterface;
- if(!QDBusConnection::connectToBus(QDBusConnection::SessionBus,QString("c2box")).isConnected()) {
-
fprintf(stderr, "Cannot connect to the D-Bus session bus.\n"
-
"To start it, run:\n"
-
"\teval `dbus-launch --auto-syntax`\n");
-
return;
-
}
-
dbusIterface = new QDBusInterface(DBUS_SERVICE_NAME, DBUS_PLAYER_SETTING_PATH, "", QDBusConnection::connectToBus(QDBusConnection::SessionBus,QString("c2box")), parent);
-
if ((dbusIterface!=NULL) && !dbusIterface->isValid()) {
-
delete dbusIterface;
-
dbusIterface = NULL;
-
}
//通过call 调用dbus service 提供的接口GetValue,item为参数。得到返回的结果为int类型的QDBusReply
QDBusReply
reply = dbusIterface->call("GetValue", item);
if (reply.isValid()) {
int value = reply.value();
//通过call 调用dbus service 提供的接口GetString,item为参数。得到返回的结果为QString类型的//QDBusReply
QDBusReply reply = dbusIterface->call("GetString", item);
if (reply.isValid()) {
return reply.value();
}
推出客户端时候:
if (dbusIterface!=NULL)
delete dbusIterface;