【发布时间】:2016-06-13 08:22:24
【问题描述】:
我尝试通过以下方式使用 Qt through DBus 设置系统时间:
#include <QDBusConnection>
#include <QDBusInterface>
#include <QDBusMessage>
#include <QDebug>
#include <QDateTime>
#include <cstdlib>
int main (int /*argc*/, char ** /*argv*/)
{
QDBusConnection dbConnection = QDBusConnection::systemBus ();
QDBusInterface dbInterface (
"org.freedesktop.timedate1.set-time"
, "/org/freedesktop/timedate1/set-time/Manager"
, "org.freedesktop.timedate1.set-time.Manager"
, dbConnection);
qDebug () << "DBus interface validation: " << dbInterface.isValid ();
if (dbInterface.isValid () ) {
QDBusMessage dbMessage = dbInterface.call ("SetTime", QDateTime::currentDateTime ().toMSecsSinceEpoch () * 1000, false, false);
qDebug () << "DBus message: " << dbMessage;
}
return EXIT_SUCCESS;
}
但我有:DBus interface validation: false。
如果我在控制台中调用:
$ gdbus introspect \
--system \
--dest org.freedesktop.timedate1 \
--object-path /org/freedesktop/timedate1
我得到了一些相关的输出(所以看起来环境没有问题):
node /org/freedesktop/timedate1 {
interface org.freedesktop.DBus.Peer {
...
};
interface org.freedesktop.DBus.Introspectable {
...
};
interface org.freedesktop.DBus.Properties {
methods:
...
signals:
...
properties:
};
interface org.freedesktop.timedate1 {
methods:
SetTime(in x arg_0,
in b arg_1,
in b arg_2);
...
signals:
properties:
...
};
};
源代码和构建脚本可在GitLab 获得。
【问题讨论】:
-
看起来对象需要被实例化。当我查看
d-feet时 - 它不存在。然后我从终端启动$ gdbus introspect --system --dest org.freedesktop.timedate1 --object-path /org/freedesktop/timedate1- timedate1 出现(然后 Qt 应用程序将其报告为有效)。 -
@Velkan,
Looks like the object needs to be instantiated.我不熟悉 D-Bus。你能解释一下我到底应该怎么做吗?
标签: qt dbus freedesktop.org