我anaconda4在我的ubuntu上安装了我的Python上有这些模块:
dbus-python (1.2.4)
gi (1.2)
pydbus (0.2)
QtAwesome (0.3.2)
qtconsole (4.2.0)
QtPy (1.0)
sip (4.18)
Run Code Online (Sandbox Code Playgroud)
我尝试安装dbus-python (1.2.4)和pydbus (0.2),但是,无论他们的作品!
在python 3.5.1中测试一个简单的程序后,出现了一个错误:
import dbus
system_bus = dbus.SystemBus()
ImportError: No module named 'dbus'
Run Code Online (Sandbox Code Playgroud)
当我pydbus在Python 2.7.11和3.5.1中使用时:
from pydbus import SystemBus
bus = SystemBus()
systemd = bus.get(".systemd1")
for unit in systemd.ListUnits():
print(unit)
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
ImportError: No module named repository
Run Code Online (Sandbox Code Playgroud)
唯一可行的就是这个例子跟PyQT4我没有任何教程.
问题是什么?是我的装置还是其他什么?
我正在尝试创建一个在系统总线上运行的守护程序服务,其中从此服务发送和接收的权限应该完全对任何人开放.(安全性不是此服务的关注点).当我尝试使用QtDbus(使用PyQt)注册服务时,我收到此错误:Connection ":1.0" is not allowed to own the service "org.dbus.arduino" due to security policies in the configuration file.这个其他堆栈溢出具有相同的错误,但由于某种原因在这种情况下根本没有帮助.dbus_bus_request_name ():不允许连接拥有该服务.
通常你应该保留system.conf文件,并在目录中添加你的权限"打出"配置文件system.d.我已经做到了这一点,但它似乎没有改变任何东西,无论我如何打开我的权限.事实上,我几乎是积极的,它没有改变任何东西!这是我的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="myUser">
<allow own="*"/>
<allow own="org.dbus.arduino"/>
<allow send_type="method_call" log="true"/>
</policy>
<policy user="root">
<allow own="*"/>
<allow own="org.dbus.arduino"/>
<allow send_type="method_call" log="true"/>
</policy>
<policy context="default">
</policy>
</busconfig>
Run Code Online (Sandbox Code Playgroud)
即使我这样做或类似的东西,它仍然不起作用.
<busconfig>
<policy context="default">
<allow own="*"/>
<allow own="org.dbus.arduino"/>
<allow send_type="method_call" log="true"/>
</policy>
</busconfig>
Run Code Online (Sandbox Code Playgroud)
我甚至把文件的名称以az开头,以便它可能是最后一个读入的文件.这是system.conf文件,注意我已经注释掉了"允许自己"部分.这是使其工作的唯一方法(以及最糟糕的"修复").
<!DOCTYPE busconfig PUBLIC …Run Code Online (Sandbox Code Playgroud) 我正在使用该qdbusxml2cpp工具为我的D-Bus服务器生成D-Bus适配器类.但是,它有以下缺点:
代码生成一次,然后您不应该修改它.但是,如果我们必须进行更改(见下文)然后更改XML(当然是以向后兼容的方式),该怎么办?
假设"适配器"具有与D-Bus接口完全相同的功能和签名.就我而言,这并不完全正确,例如,某些方法的命名方式不同.由于生成的代码使用QMetaObject::invokeMethod,因此仅在运行时检测到.如果我们将来需要重新生成代码,我们就无法明智地修改生成的代码.
在我看来,如果qdbusxml2cpp生成一个抽象类,只是一个标题,所有方法都是纯虚拟的,那就更好了.然后我可以编写一个类的实现,只需调用适配器上的正确方法,而无需通过Qt元类型系统.这解决了两个问题:
如果XML发生变化,我们只需重新生成标题.现在编译器会抱怨,直到我们正确实现新接口.
我们可以自由地在"adaptee"类中调用我们喜欢的任何函数,而不是保持与公共D-Bus接口中完全相同的签名.
我找不到上述任何工具或qdbusxml2cpp叉子.在我自己编写之前,上述方法是否存在任何问题,我可能会忽略,设计方面还是技术方面?也许元类型系统的局限性与抽象类或纯虚函数有关?
请注意,我需要这不仅可以使用方法,还可以使用属性和信号.
我还考虑编写一个包含"adaptee"的"中间"适配器,并提供D-Bus适配器所需的确切接口,但D-Bus适配器仍将使用元类型系统和运行时检查.当然,我们可以做得更好.
我想使用 Qt Creator 中的 Qt Dbus 在系统总线上公开我的应用程序的方法。使用会话总线时,方法会被暴露,但使用系统总线时,我只能看到我注册的服务名称,但在其下看不到暴露的方法。(我正在 D-feet 中检查它)我应该做什么?
我正在尝试创建利用 D-Bus 的程序。我研究了 Qt 提供的示例,大致相同。在其中一个名为“D-Bus 遥控车示例”中,有一个名为“car.xml”的文件,内容如下:
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
<node name="/com/trollech/examples/car">
<interface name="org.example.Examples.CarInterface">
<method name="accelerate"/>
<method name="decelerate"/>
<method name="turnLeft"/>
<method name="turnRight"/>
<signal name="crashed"/>
</interface>
</node>
Run Code Online (Sandbox Code Playgroud)
如果我没记错的话,应该使用名为“qdbuscpp2xml”的工具生成此文件。当我使用此命令生成 xml 时:
$ qdbuscpp2xml -A car.h -o car2.xml
Run Code Online (Sandbox Code Playgroud)
我在生成的 XML 文件中得到以下内容:
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
<node>
<interface name="local.Car">
<signal name="crashed">
</signal>
<method name="accelerate">
</method>
<method name="decelerate">
</method>
<method name="turnLeft">
</method>
<method name="turnRight">
</method>
</interface>
</node>
Run Code Online (Sandbox Code Playgroud)
它与 car.xml 的不同之处在于以下几行:
<node name="/com/trollech/examples/car">
<interface name="org.example.Examples.CarInterface">
Run Code Online (Sandbox Code Playgroud)
为什么我得到一个不同的文件?示例中包含的文件 …
我有一个绑定到D-Bus的QT/C++终端应用程序,但是当我尝试在会话总线上绑定时,我收到以下错误:
"无法在没有$ DISPLAY for X11的情况下自动启动dbus-daemon"
这只是一个简单的终端应用程序,代码片段:
if (!QDBusConnection::sessionBus().isConnected()) {
fprintf(stderr, "Cannot connect to the D-Bus session bus.\n"
"To start it, run:\n"
"\teval `dbus-launch --auto-syntax`\n");
fprintf(stderr, "%s\n",
qPrintable(QDBusConnection::sessionBus().lastError().message()));
return 1;
}
Run Code Online (Sandbox Code Playgroud)
我不需要X11支持,所以我只是寻找最简单的方法来处理这个错误
我正在尝试使用Qt的QDBus类库调用WPA请求者的DBus接口.特别是,我正在尝试使用"Get"属性调用来检索"Interfaces"属性值.
"获取"的DBus规范(通过内省)是:
<interface name="org.freedesktop.DBus.Properties">
<method name="Get">
<arg name="interface" type="s" direction="in"/>
<arg name="propname" type="s" direction="in"/>
<arg name="value" type="v" direction="out"/>
</method>
...
</interface>
Run Code Online (Sandbox Code Playgroud)
看起来很简单.输入两个字符串,输出是变量(这些是DBus类型).对于"Interfaces"属性,我期望变量是一个对象路径数组(DBus类型"ao").
我QDBusInterface::call()用来调用DBus方法,它返回一个QDBusMessage,但我无法弄清楚如何从中提取数据.
QDBusMessage::arguments()返回一个QList<QVariant>.为了找到我的对象路径数组,我尝试了对此列表中项目的各种转换,但我似乎最终得到了一个空字符串.
QVariant::type()看起来它应该有所帮助,但它似乎只返回类型QDBusMessage,这显然是错误的.例如:
// 'message' is of type QDBusMessage
qDebug() << "Argument 0 type is" << message.arguments().at(0).type();
Run Code Online (Sandbox Code Playgroud)
打印:
Argument 0 type is QVariant::QDBusMessage
Run Code Online (Sandbox Code Playgroud)
如何提取实际的消息数据?
我正在尝试将UDisks2与 Qt 应用程序连接,并且读取自定义属性会使程序崩溃。
对于 SMART 属性,一切正常(包括自定义属性),但是当我尝试读取 RAID 设备属性ActiveDevices时,出现 Qt 致命错误并且应用程序崩溃
以下是说明该行为的测试程序:
#include <QApplication>
#include <QDBusMetaType>
#include <QDBusConnection>
#include <QDBusInterface>
#include <QDebug>
//create the structure as defined in
// http://udisks.freedesktop.org/docs/latest/gdbus-org.freedesktop.UDisks2.MDRaid.html#gdbus-property-org-freedesktop-UDisks2-MDRaid.ActiveDevices
struct MDRaidMember {
QDBusObjectPath block;
qint32 slot;
QStringList state;
qint64 numReadErrors;
QVariantMap expansion;
};
Q_DECLARE_METATYPE(MDRaidMember)
//marshalling operator
QDBusArgument &operator<<(QDBusArgument &argument, const MDRaidMember& raidMember)
{
argument.beginStructure();
argument << raidMember.block;
argument << raidMember.slot;
argument << raidMember.state;
argument << raidMember.numReadErrors;
argument << raidMember.expansion;
argument.endStructure();
return argument;
}
//unmarshall …Run Code Online (Sandbox Code Playgroud) 当我运行 Qt Creator dbus 示例时,它们无法运行,是否有任何用于工作 QtDbus 模块的设置或内容或任何先决条件?
例如在chat项目中:
if (!QDBusConnection::sessionBus().isConnected()) {
qWarning("Cannot connect to the D-Bus session bus.\n"
"Please check your system settings and try again.\n");
return 1;
}
Run Code Online (Sandbox Code Playgroud)
返回1并且程序终止。
我试图使用PyQt4在DBus上运行一些基本代码,特别是QtDBus.我正在使用Python3版本的PyQt4.我已经得到了我想在Qt(c ++)上运行的代码但是我想要使用Python运行类似的代码.我想在DBus上公开方法,信号/槽和属性,以便调用其他Python代码.
在Qt中,您使用Q_CLASSINFO宏/函数进行DBus内省.虽然我已经引入了Q_CLASSINFO方法,但我无法让它产生相同类型的功能.据我所知,Q_CLASSINFO方法没有文档,所以我不确定是否还有其他方法.使用D-Feet我可以清楚地看到没有自动暴露的方法,所以我有点卡住了.
这是我到目前为止所拥有的.
from PyQt4 import QtDBus
from PyQt4.QtCore import QCoreApplication, QObject, Q_CLASSINFO, pyqtSlot, pyqtProperty
from PyQt4.QtDBus import QDBusConnection, QDBusAbstractAdaptor
SERVICE = 'com.home.dbus'
class MyServer(QObject):
def __init__(self):
QObject.__init__(self)
self.__dbusAdaptor = ServerAdaptor(self)
def close(self):
pass
def echo(self, value):
echoed = 'Received {0}'.format(value)
return echoed
def name(self):
return 'myname'
def dbus_adaptor(self):
return self.__dbusAdaptor
class ServerAdaptor(QDBusAbstractAdaptor):
""" This provides the DBus adaptor to the outside world"""
def __init__(self, parent):
super().__init__(parent)
self.__parent = parent
Q_CLASSINFO("D-Bus Introspection",
" <interface name=\"com.home.dbus\">\n"
" <method name=\"name\">\n"
" …Run Code Online (Sandbox Code Playgroud) qtdbus ×11
dbus ×10
qt ×7
c++ ×4
python ×2
qdbus ×2
enums ×1
ipc ×1
linux ×1
pyqt4 ×1
python-2.7 ×1
python-3.x ×1
qdbusxml2cpp ×1
qt5.4 ×1