相关疑难解决方法(0)

如何使用带有PyQt4的QDBusAbstractAdaptor在DBus上公开方法和属性?

我试图使用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)

python qt dbus pyqt4 qtdbus

2
推荐指数
1
解决办法
2173
查看次数

标签 统计

dbus ×1

pyqt4 ×1

python ×1

qt ×1

qtdbus ×1