如何使用“ QDbusConnection”将“ org.freedesktop.DBus.Properties”的“ PropertiesChanged”信号正确连接到QT中的插槽?

如何解决如何使用“ QDbusConnection”将“ org.freedesktop.DBus.Properties”的“ PropertiesChanged”信号正确连接到QT中的插槽?

我正在实现与嵌入式设备的接口,该接口通过dbus API公开其硬件配置。

目前,我正在研究对设备的硬件I / O引脚的访问。在配置和读取/写入这些引脚时,已经可以按预期方式工作了,但在将这些输入引脚的 PropertiesChanged 信号正确连接到我的qt应用程序的插槽时,我遇到了问题。该信号通知监听者该引脚上当前输入值的变化。

例如,通过dbus-monitor发出信号时,信号如下所示:

signal sender=:1.2 -> dest=(null destination) serial=1023 path=/com/actia/platform/io/freq_in1_std; interface=org.freedesktop.DBus.Properties; member=PropertiesChanged
   string "com.actia.platform.io.digital_input"
   array [
      dict entry(
         string "InputValue"
         variant             int32 17857
      )
   ]
   array [
   ]

代表施加的频率1.7857 kHz的值。

我这样连接到信号:

    if (QDBusConnection::sessionBus().connect("com.actia.platform.io","/com/actia/platform/io/freq_in1_std","org.freedesktop.DBus.Properties","PropertiesChanged",this,SLOT(propertyChanged(QString,QVariantMap,QStringList)))) {
        qDebug() << "PropertiesChanged signal connected successfully to slot";
        } else {
            qDebug() << "PropertiesChanged signal connection was not successful";
        }

,连接的插槽如下:

void MyClass::propertyChanged(QString name,QVariantMap map,QStringList list)
    {
        qDebug() << QString("properties of interface %1 changed").arg(name);
        for (QVariantMap::const_iterator it = map.cbegin(),end = map.cend(); it != end; ++it) {
            qDebug() << "property: " << it.key() << " value: " << it.value();
        }
        for (const auto& element : list) {
            qDebug() << "list element: " << element;
        }
    }

我看到连接成功完成,但是我认为签名似乎不正确。因为我从来没有看到那个插槽被调用。

这是调试输出的摘录,其中包含一个小示例应用程序类的QDBUS_DEBUG=1,在该实例中,我实例化了一个输入和一个输出引脚,在其中我连接了 PropertiesChanged 信号,然后访问了一些手动设置dbus方法和属性,然后使其空转以等待信号捕获。我评论了一下调试日志。一段时间后,当dbus上的信号被触发多次后,我退出了该应用程序。

### application.debug: start of initialization before issuing QCoreApplication::exec()...
### application.debug: creating a digital out pin...
// comment on the logs: The folloiwing 6 lines of debug output originate of instanciating the matching dbus proxy that has been generated by qdbusxml2cpp
QDBusConnectionPrivate(0x747021d0) : connected successfully
QDBusConnectionPrivate(0x747021d0) got message (signal): QDBusMessage(type=Signal,service="org.freedesktop.DBus",path="/org/freedesktop/DBus",interface="org.freedesktop.DBus",member="NameAcquired",signature="s",contents=(":1.1464") )
QDBusConnectionPrivate(0x747021d0) delivery is suspended
QDBusConnectionPrivate(0x747021d0) Adding rule: "type='signal',sender='org.freedesktop.DBus',interface='org.freedesktop.DBus',member='NameOwnerChanged',arg0='com.actia.platform.io'"
QDBusConnectionPrivate(0x747021d0) sending message: QDBusMessage(type=MethodCall,member="GetNameOwner",signature="",contents=("com.actia.platform.io") )
QDBusConnectionPrivate(0x747021d0) got message reply: QDBusMessage(type=MethodReturn,contents=(":1.2") )
### application.debug: Connecting the PropertiesChanged signal for the created pin...
QDBusConnectionPrivate(0x74710460) : connected successfully
QDBusConnectionPrivate(0x74710460) got message (signal): QDBusMessage(type=Signal,contents=(":1.28") )
QDBusConnectionPrivate(0x74710460) delivery is suspended
QDBusConnectionPrivate(0x74710460) Adding rule: "type='signal',sender='com.actia.platform.io',path='/com/actia/platform/io/dout1',interface='org.freedesktop.DBus.Properties',member='PropertiesChanged'"
QDBusConnectionPrivate(0x74710460) sending message: QDBusMessage(type=MethodCall,contents=("com.actia.platform.io") )
QDBusConnectionPrivate(0x74710460) got message reply: QDBusMessage(type=Error,error name="org.freedesktop.DBus.Error.NameHasNoOwner",error message="Could not get owner of name 'com.actia.platform.io': no such name",contents=("Could not get owner of name 'com.actia.platform.io': no such name") )
QDBusConnectionPrivate(0x74710460) Watching service "com.actia.platform.io" for owner changes (current owner: "" )
### application.debug: PropertiesChanged signal connected successfully to slot
### application.debug: creating a digital in pin...
// comment on the logs: The following 2 lines of debug output originate of instanciating the matching dbus proxy that has been generated by qdbusxml2cpp
QDBusConnectionPrivate(0x747021d0) sending message: QDBusMessage(type=MethodCall,contents=(":1.2") )
### application.debug: Connecting the PropertiesChanged signal for the created pin...
QDBusConnectionPrivate(0x74710460) Adding rule: "type='signal',path='/com/actia/platform/io/freq_in1_std',member='PropertiesChanged'"
### application.debug: PropertiesChanged signal connected successfully to slot
### application.debug: success setting pin modes for the digital out pin to pwm generation:  true
// comment on the logs: setting a value on an output pin now
QDBusConnectionPrivate(0x747021d0) sending message: QDBusMessage(type=MethodCall,service="com.actia.platform.io",path="/com/actia/platform/io/dout1",interface="com.actia.platform.io.digital_output",member="SetValue",contents=(200,80) )
QDBusConnectionPrivate(0x747021d0) got message reply: QDBusMessage(type=MethodReturn,service=":1.2",contents=() )
### application.debug: success setting pwm of 20 Hz at 80% duty cycle:  true
// comment on the logs: reading back the properties for the pins to verify
QDBusConnectionPrivate(0x747021d0) sending message: QDBusMessage(type=MethodCall,interface="org.freedesktop.DBus.Properties",member="Get",contents=("com.actia.platform.io.digital_output","OutputFrequency") )
QDBusConnectionPrivate(0x747021d0) got message reply: QDBusMessage(type=MethodReturn,signature="v",contents=([Variant(int): 200]) )
QDBusConnectionPrivate(0x747021d0) sending message: QDBusMessage(type=MethodCall,"OutputRatio") )
QDBusConnectionPrivate(0x747021d0) got message reply: QDBusMessage(type=MethodReturn,contents=([Variant(int): 80]) )
### application.debug: pwm backread frequency 20,duty cycle 80
// comment on the logs: setting the mode of a digital input pin to read a frequency instead a logical 0 or 1
QDBusConnectionPrivate(0x747021d0) sending message: QDBusMessage(type=MethodCall,path="/com/actia/platform/io/freq_in1_std",interface="com.actia.platform.io.digital_input",member="SetInputType",contents=(2) )
QDBusConnectionPrivate(0x747021d0) got message reply: QDBusMessage(type=MethodReturn,contents=() )
### application.debug: setting pin modes of the digital in pin to read a frequency:  true
// comment on the logs: reading the currently applied frequency from the pin now
QDBusConnectionPrivate(0x747021d0) sending message: QDBusMessage(type=MethodCall,contents=("com.actia.platform.io.digital_input","InputValue") )
QDBusConnectionPrivate(0x747021d0) got message reply: QDBusMessage(type=MethodReturn,contents=([Variant(int): 17361]) )
### application.debug: reading the current frequency from digital input:  1736.1  Hz
### application.debug: end of actual code during initialization,now issuing QCoreApplication::exec()...
QDBusConnectionPrivate(0x747021d0) dequeueing message QDBusMessage(type=Signal,contents=(":1.1464") )
QDBusConnectionPrivate(0x74710460) dequeueing message QDBusMessage(type=Signal,contents=(":1.28") )
[...] program running,waiting for signals
### application.debug: QCoreApplication::quit()
QDBusConnectionPrivate(0x74710460) Removing rule: "type='signal',member='PropertiesChanged'"
QDBusConnectionPrivate(0x74710460) Removing rule: "type='signal',member='PropertiesChanged'"
QDBusConnectionPrivate(0x747021d0) Disconnected
QDBusConnectionPrivate(0x74710460) Disconnected

我在SO或QT论坛上找到了大量关于连接到 PropertiesChanged 信号的建议,并从那里尝试了一些建议,但无济于事。必须存在一些我不知道的签名不匹配。但是,我偷看了诸如networkmanager-qt之类的dbus应用程序的代码,它们使用了我也在签名中使用的三个参数:QStringQVariantMapQStringList。 / p>

我现在陷入困境,希望任何人都可以提出其他提示。 预先感谢。

解决方法

嗯,我真的不知道为什么。但是,当我使用全新的源qt构建(与以前的版本相同)再次尝试上述确切代码时,它就可以工作。所以我认为目前已经解决了。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


依赖报错 idea导入项目后依赖报错,解决方案:https://blog.csdn.net/weixin_42420249/article/details/81191861 依赖版本报错:更换其他版本 无法下载依赖可参考:https://blog.csdn.net/weixin_42628809/a
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下 2021-12-03 13:33:33.927 ERROR 7228 [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPL
错误1:gradle项目控制台输出为乱码 # 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302 # 在gradle-wrapper.properties 添加以下内容 org.gradle.jvmargs=-Df
错误还原:在查询的过程中,传入的workType为0时,该条件不起作用 &lt;select id=&quot;xxx&quot;&gt; SELECT di.id, di.name, di.work_type, di.updated... &lt;where&gt; &lt;if test=&qu
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员 redisSetCpuAffinity(server.server_cpulist); ^ server.c: 在函数‘hasActiveC
解决方案1 1、改项目中.idea/workspace.xml配置文件,增加dynamic.classpath参数 2、搜索PropertiesComponent,添加如下 &lt;property name=&quot;dynamic.classpath&quot; value=&quot;tru
删除根组件app.vue中的默认代码后报错:Module Error (from ./node_modules/eslint-loader/index.js): 解决方案:关闭ESlint代码检测,在项目根目录创建vue.config.js,在文件中添加 module.exports = { lin
查看spark默认的python版本 [root@master day27]# pyspark /home/software/spark-2.3.4-bin-hadoop2.7/conf/spark-env.sh: line 2: /usr/local/hadoop/bin/hadoop: No s
使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams[&#39;font.sans-serif&#39;] = [&#39;SimHei&#39;] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -&gt; systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping(&quot;/hires&quot;) public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate&lt;String
使用vite构建项目报错 C:\Users\ychen\work&gt;npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-