void TimeAndLanguageManager::listenPropertyChange()
{
auto dbusInterfaceProperty = new QDBusInterface("org.freedesktop.timedate1",
"/org/freedesktop/timedate1",
"org.freedesktop.timedate1",
QDBusConnection::systemBus());
if (!dbusInterfaceProperty->isValid()) {
qDebug() << "DBus interface is not valid.";
return;
}
connect(dbusInterfaceProperty, SIGNAL(PropertyChanged(QString,QVariant)), this, [this](const QString &propertyName, const QVariant &value){
if (propertyName == "TimeUSec") {
qDebug() << "Property TimeUSec changed to" << value;
emit timeChange();
}
});
}
在这个示例中,连接到了指定接口的对象,并监听其 `PropertyChanged` 信号。在信号槽函数中,我们检查属性名称是否为 `TimeUSec`,如果是,则发出信号 `timeChange()`。