我正在尝试使用QtDbusPowerManager
与我系统中提供的接口进行通信。我的目标很简单。我将编写代码,使我的系统使用 DBus 接口休眠。
所以,我安装了d-feet应用程序来查看我的系统上有哪些接口 DBus可用,以及我看到了什么:
正如我们所看到的,我有一些接口和方法可以从中选择一些东西。我的选择是Hibernate(),来自接口org.freedesktop.PowerManagment
在这个目标中,我准备了一些非常简单的代码来只了解机制。我当然使用了Qt库:
#include <QtCore/QCoreApplication>
#include <QtCore/QDebug>
#include <QtCore/QStringList>
#include <QtDBus/QtDBus>
#include <QDBusInterface>
int main(int argc, char **argv)
{
QCoreApplication app(argc, argv);
if (!QDBusConnection::sessionBus().isConnected()) {
fprintf(stderr, "Cannot connect to the D-Bus session bus.\n"
"To start it, run:\n"
"\teval `dbus-launch --auto-syntax`\n");
return 1;
}
QDBusInterface iface("org.freedesktop.PowerManagement" ,"/" , "" , QDBusConnection::sessionBus());
if(iface.isValid())
{
qDebug() << "Is good";
QDBusReply<QString> reply = iface.call("Methods" , "Hibernate");
if(reply.isValid())
{
qDebug() << "Hibernate by by " << qPrintable(reply.value());
}
qDebug() << "some error " << qPrintable(reply.error().message());
}
return 0;
}
不幸的是,我的终端出现错误:
接口“(null)”上带有签名“s”的
一些错误方法“方法”不存在
所以请告诉我这段代码有什么问题?我确定我忘记了函数QDBusInterface::call()中的一些参数,但是什么?