PyQt5在dbus请求失败时创建错误

2024-09-30 05:18:27 发布

您现在位置:Python中文网/ 问答频道 /正文

使用PyQt5的D-Bus,如何创建错误?例如,如果有人在聊天程序中发送一个未知命令,我希望能够让客户端知道如下内容:

error = QDBusMessage.createError(QDBusError.UnknownProperty, "unknown command")
QDBusConnection.systemBus().send(error)

但是,此操作失败,并显示以下消息:

*** TypeError: arguments did not match any overloaded call:
  createErrorReply(self, str, str): first argument of unbound method must have type 'QDBusMessage'
  createErrorReply(self, QDBusError): first argument of unbound method must have type 'QDBusMessage'
  createErrorReply(self, QDBusError.ErrorType, str): first argument of unbound method must have type 'QDBusMessage'

我不知道这个错误到底是怎么回事,因为据我所知,我使用它完全符合描述。第一个参数必须是QDBusMessage,因为它在点之前。第二个参数是正确的类型,<class 'PyQt5.QtDBus.QDBusError.ErrorType'>type(QDBusError.UnknownProperty)返回。引号表示它是一个字符串,这就是str。你知道吗

我也尝试过sendErrorReply(),但在PyQt5中似乎不存在这种情况。至少,我找不到它-它不在systemBussend()旁边,也不在QDBusMessage里。你知道吗

PyQt5的examples/dbus/chat文件夹中的两个示例都不会发出错误。在http://pyqt.sourceforge.net/Docs/PyQt5/QtDBus.html没有可用的Python文档。你知道吗


Tags: ofselfhavetype错误argumentmethodpyqt5

热门问题