c++ - qdbusxml2cpp 无法正常工作

标签 c++ qt embedded-linux qtdbus

我正在做一个基于 Qt 的小应用程序,以便在我的嵌入式 Linux 附近获取所有 Wifi 承载,为此我将 Connman 与 QtDBus 结合使用。为了获取所有 wifi 信号,我尝试使用 qdbusxml2cpp 应用程序获取自动生成的适配器代码。为此,我使用 connman-dbus.conf 文件作为具有以下内容的服务描述:

   <!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"
 "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
<busconfig>
    <policy user="root">
        <allow own="net.connman"/>
        <allow send_destination="net.connman"/>
        <allow send_interface="net.connman.Agent"/>
        <allow send_interface="net.connman.Counter"/>
        <allow send_interface="net.connman.Notification"/>
    <allow send_interface="net.connman.Manager"/>
    </policy>
    <policy at_console="true">
        <allow send_destination="net.connman"/>
    </policy>
    <policy context="default">
        <deny send_destination="net.connman"/>
    </policy>
</busconfig>

然后,我执行下一个命令:

$ qdbusxml2cpp -N -v /etc/dbus-1/system.d/connman-dbus.conf -a connmandbusexample.h:connmandbusexample.cpp

但是这样做的结果是下面的代码:

connmandbusexample.cpp

/*
 * This file was generated by qdbusxml2cpp version 0.8
 * Command line was: qdbusxml2cpp -N -v /etc/dbus-1/system.d/connman-dbus.conf -a connmandbusexample.h:connmandbusexample.cpp
 *
 * qdbusxml2cpp is Copyright (C) 2015 Digia Plc and/or its subsidiary(-ies).
 *
 * This is an auto-generated file.
 * Do not edit! All changes made to it will be lost.
 */

#include "connmandbusexample.h"
#include <QtCore/QMetaObject>
#include <QtCore/QByteArray>
#include <QtCore/QList>
#include <QtCore/QMap>
#include <QtCore/QString>
#include <QtCore/QStringList>
#include <QtCore/QVariant>

connmandbusexample.h

/*
 * This file was generated by qdbusxml2cpp version 0.8
 * Command line was: qdbusxml2cpp -N -v /etc/dbus-1/system.d/connman-dbus.conf -a connmandbusexample.h:connmandbusexample.cpp
 *
 * qdbusxml2cpp is Copyright (C) 2015 Digia Plc and/or its subsidiary(-ies).
 *
 * This is an auto-generated file.
 * This file may have been hand-edited. Look for HAND-EDIT comments
 * before re-generating it.
 */

#ifndef CONNMANDBUSEXAMPLE_H_1462807819
#define CONNMANDBUSEXAMPLE_H_1462807819

#include <QtCore/QObject>
#include <QtDBus/QtDBus>
QT_BEGIN_NAMESPACE
class QByteArray;
template<class T> class QList;
template<class Key, class Value> class QMap;
class QString;
class QStringList;
class QVariant;
QT_END_NAMESPACE

#endif

如您所见,这段代码没有用,所以我想知道我是否对 qdbusxml2cpp 做错了什么。另外,我不知道我是否可以通过使用 QtDBus 的其他更正确的方法来做到这一点。最后,是否可以从不使用 root 权限的 Qt App 连接到 wifi 网络?我认为以上所有都是非常相关的问题,可以帮助解决这个问题。

最佳答案

您要转换的文件是 DBus 守护程序的配置文件,而不是 DBus 接口(interface)的接口(interface)规范。它仅描述允许在总线上将哪些信号从 conman 发送到/发送到 conman,而不是它们的外观。

您需要转换正确的接口(interface) xml,它应该类似于 this .建议使用您正在使用的 conman 的确切版本的接口(interface)规范,我只是从 github 中提取了最新的主干版本作为示例。

您可以在 xml(内省(introspection)格式)中找到有关 DBus 接口(interface)描述的更多信息 here .

我不熟悉 conman 的功能,或者它的哪一部分功能可以通过 D-Bus 访问,但在快速浏览了 these notes 之后看起来您应该能够通过该接口(interface)扫描可用接口(interface) - 尝试使用 net.connman.Technology.Scan 方法。

一般来说使用QDbus是没有问题的,文档上什至是这样写的:

It should be noted that the low-level implementation is not primarily designed for application authors to use. Rather, it is a basis for binding authors and a reference for reimplementations. If you are able to do so it is recommended that you use one of the higher level bindings or implementations.

QtDBus 是 those higher level bindings 之一.

关于c++ - qdbusxml2cpp 无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37119807/

相关文章:

arm - 从 linux 交叉编译到 ARM-ELF (armv5tejl )

c++ - while 循环表达式

c++ - 由于为 C++ 程序调用 ulldiv.asm 而导致编译器引用错误

c++ - 在多线程程序中使用管道与子通信

c++ - 如何在 qt 4.6.3 中取消触摸事件?

c++ - Qt:QProcess 结果与提示时的结果不匹配

c++ - QVariantMap DBusMenuExporterDBus GLib-GObject-CRITICAL GLib-GObject-警告

c - 使用 C 的 Beaglebone 黑色 PWM

c++ - 获取错误 "Expression: string subscript out of range"

linux - 为什么 OpenSSL 1.1 中 ECC 签名验证需要随机数(有时需要很长时间)?