如何在qt dbus呼叫中从qdbusmessage转换到QString C++
在下面的代码中,我获得了有关单元调制解调器的信息。结果是我期望的数据。现在,我需要将“结果”转换为QString,以便我可以处理数据并获取对象路径或直接提取对象路径。我已经尝试了多种转换结果的方法,但是他们要么抛出无法转换qdbusmessage错误或返回空字符串。任何人都可以指向正确的方向。预先感谢
QDBusInterface interface( "org.ofono",
"/",
"org.ofono.Manager",
QDBusConnection::systemBus() );
QDBusMessage result = interface.call( "GetModems");
qDebug() << "we got a" << result ;
//the last thing I tried was
QString eventReceivedName= result.arguments().at(0).value<QString>();//makes a empty string
这是Qdebug的输出,这是我所期望的。
QDBusMessage(type=MethodReturn, service=":1.4", signature="a(oa{sv})", contents=([Argument: a(oa{sv}) {[Argument: (oa{sv}) [ObjectPath: /hfp/org/bluez/hci0/dev_XX_0D_XX_81_XX_98], [Argument: a{sv} {"Online" = [Variant(bool): false], "Powered" = [Variant(bool): false], "Lockdown" = [Variant(bool): false], "Emergency" = [Variant(bool): false], "Interfaces" = [Variant(QStringList): {}], "Features" = [Variant(QStringList): {}], "Name" = [Variant(QString): "moto g power"], "Type" = [Variant(QString): "hfp"]}]]}]) )
In the code below I am getting info about my cell modem. The result is the data that I expect. Now I need to convert "result" to a QString so I can process the data and get the object path or just extract the Object Path directly. I have tried various ways to convert result but they either throw a unable to convert qdbusmessage error or return a empty string. Can anyone point me in the right direction. Thanks in advance
QDBusInterface interface( "org.ofono",
"/",
"org.ofono.Manager",
QDBusConnection::systemBus() );
QDBusMessage result = interface.call( "GetModems");
qDebug() << "we got a" << result ;
//the last thing I tried was
QString eventReceivedName= result.arguments().at(0).value<QString>();//makes a empty string
This is the output from qDebug and it is what I am expecting.
QDBusMessage(type=MethodReturn, service=":1.4", signature="a(oa{sv})", contents=([Argument: a(oa{sv}) {[Argument: (oa{sv}) [ObjectPath: /hfp/org/bluez/hci0/dev_XX_0D_XX_81_XX_98], [Argument: a{sv} {"Online" = [Variant(bool): false], "Powered" = [Variant(bool): false], "Lockdown" = [Variant(bool): false], "Emergency" = [Variant(bool): false], "Interfaces" = [Variant(QStringList): {}], "Features" = [Variant(QStringList): {}], "Name" = [Variant(QString): "moto g power"], "Type" = [Variant(QString): "hfp"]}]]}]) )
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
因此,在吹牛院子里并在Google上花了几个小时后,我终于确定了“结果”中的单个参数是一个关键,价值,地图。然后,随着更多的搜索,我找到了代码来从地图中提取数据。它返回
/hfp/org/bluez/hci0/dev_xx_xx_xx_xx_xx_xx_xx_xx
正是我需要的。工作代码在下面。感谢大家的答复。So after blowing off mowing the yard and spending a couple more hours on google I finally determined that the single argument that is in "result" is a key, value, map. Then with a little more searching I found the code to extract the data from the map. It returns
/hfp/org/bluez/hci0/dev_XX_XX_XX_XX_XX_XX
Exactly what I needed. The working code is below. Thanks for the replies everyone.