PySide6.QtDBus.QDBusAbstractInterface¶
- class QDBusAbstractInterface¶
QDBusAbstractInterface
类是 Qt D-Bus 绑定中所有 D-Bus 接口的基类,允许访问远程接口。更多…继承自:
QDBusInterface
,QDBusConnectionInterface
概要¶
方法¶
def
__init__()
def
asyncCall()
def
call()
def
connection()
def
interface()
def
isValid()
def
lastError()
def
path()
def
service()
def
setTimeout()
def
timeout()
注意
本文档可能包含从C++自动翻译到Python的代码片段。我们始终欢迎对代码片段翻译的贡献。如果您发现翻译问题,您也可以通过在我们的https:/bugreports.qt.io/projects/PYSIDE上创建工单来告知我们。
详细描述¶
生成的代码类也继承自
QDBusAbstractInterface
,这里描述的所有方法也适用于生成的代码类。除了这里描述的内容外,生成的代码类还提供了远程方法的成员函数,这些函数允许在编译时检查正确的参数和返回值,以及属性类型匹配和信号参数匹配。另请参阅
- __init__(service, path, interface, connection, parent)¶
- Parameters:
service – str
path – 字符串
interface – str
connection –
QDBusConnection
parent –
QObject
- asyncCall(method)¶
- Parameters:
method – str
- Return type:
- asyncCallWithArgumentList(method, args)¶
- Parameters:
method – str
args – QVariant 的列表
- Return type:
调用此接口上由
method
指定的远程方法,使用args
作为参数。此函数返回一个QDBusPendingCall
对象,该对象可用于跟踪回复的状态并在回复到达后访问其内容。通常,你应该使用
asyncCall()
进行调用。注意
由于实现限制,应用程序本身注册的对象的方法调用永远不会是异步的。
- call(method)¶
- Parameters:
method – str
- Return type:
- call(mode, method)
- Parameters:
mode –
CallMode
method – str
- Return type:
警告
本节包含从C++自动翻译到Python的代码片段,可能包含错误。
调用此接口上的方法
method
并将args
传递给该方法。所有args
必须可转换为 QVariant。call
的参数通过 D-Bus 作为输入参数传递给远程函数。输出参数在QDBusMessage
回复中返回。如果回复是错误回复,lastError()
也将设置为错误消息的内容。它可以按以下方式使用:
value = retrieveValue() reply = QDBusMessage() api = interface.call("GetAPIVersion") if api >= 14: reply = interface.call("ProcessWorkUnicode", value) else: reply = interface.call("ProcessWork", "UTF-8", value.toUtf8())
这个例子展示了使用0、1和2个参数的函数调用,并展示了每种情况下传递的不同参数类型(第一次调用
"ProcessWorkUnicode"
将包含一个Unicode字符串,第二次调用"ProcessWork"
将包含一个字符串和一个字节数组)。请参阅asyncCall()
以了解在非阻塞(异步)调用中的相同示例。- call(method, args)
- Parameters:
method – str
args – 对象
- Return type:
警告
本节包含从C++自动翻译到Python的代码片段,可能包含错误。
调用此接口上的方法
method
并将args
传递给该方法。所有args
必须可转换为 QVariant。call
的参数通过 D-Bus 作为输入参数传递给远程函数。输出参数在QDBusMessage
回复中返回。如果回复是错误回复,lastError()
也将设置为错误消息的内容。它可以按以下方式使用:
value = retrieveValue() reply = QDBusMessage() api = interface.call("GetAPIVersion") if api >= 14: reply = interface.call("ProcessWorkUnicode", value) else: reply = interface.call("ProcessWork", "UTF-8", value.toUtf8())
这个例子展示了使用0、1和2个参数的函数调用,并展示了每种情况下传递的不同参数类型(第一次调用
"ProcessWorkUnicode"
将包含一个Unicode字符串,第二次调用"ProcessWork"
将包含一个字符串和一个字节数组)。请参阅asyncCall()
以查看非阻塞(异步)调用中的相同示例。- call(mode, method, args)
- Parameters:
mode –
CallMode
method – str
args – 对象
- Return type:
这是一个重载函数。
调用此接口上的方法
method
并将args
传递给该方法。所有args
必须可转换为 QVariant。如果
mode
是NoWaitForReply
,那么此函数将在放置调用后立即返回,而无需等待远程方法的回复。否则,mode
指示此函数在等待回复到达时是否应激活 Qt 事件循环。如果此函数重新进入Qt事件循环以等待回复,它将排除用户输入。在等待期间,它可能会向您的应用程序传递信号和其他方法调用。因此,每当使用
call()
进行调用时,必须准备好处理重入。- call(mode, method, args)
- Parameters:
mode – str
method – 对象
args – 对象
- Return type:
这是一个重载函数。
调用此接口上的方法
method
并将args
传递给该方法。所有args
必须可转换为 QVariant。如果
mode
是NoWaitForReply
,那么此函数将在放置调用后立即返回,而无需等待远程方法的回复。否则,mode
指示此函数在等待回复到达时是否应激活 Qt 事件循环。如果此函数重新进入Qt事件循环以等待回复,它将排除用户输入。在等待期间,它可能会向您的应用程序传递信号和其他方法调用。因此,每当使用
call()
进行调用时,必须准备好处理重入。- call(arg__1, arg__2, arg__3, arg__4)
- Parameters:
arg__1 –
CallMode
arg__2 – 字符串
arg__3 – 对象
arg__4 – 对象
- Return type:
- call(arg__1, arg__2, arg__3, arg__4)
- Parameters:
arg__1 – str
arg__2 – 对象
arg__3 – 对象
arg__4 – 对象
- Return type:
- call(arg__1, arg__2, arg__3, arg__4, arg__5)
- Parameters:
arg__1 –
CallMode
arg__2 – 字符串
arg__3 – 对象
arg__4 – 对象
arg__5 – 对象
- Return type:
- call(arg__1, arg__2, arg__3, arg__4, arg__5)
- Parameters:
arg__1 – str
arg__2 – 对象
arg__3 – 对象
arg__4 – 对象
arg__5 – 对象
- Return type:
- call(arg__1, arg__2, arg__3, arg__4, arg__5, arg__6)
- Parameters:
arg__1 –
CallMode
arg__2 – 字符串
arg__3 – 对象
arg__4 – 对象
arg__5 – 对象
arg__6 – 对象
- Return type:
- call(arg__1, arg__2, arg__3, arg__4, arg__5, arg__6, arg__7)
- Parameters:
arg__1 –
CallMode
arg__2 – 字符串
arg__3 – 对象
arg__4 – 对象
arg__5 – 对象
arg__6 – 对象
arg__7 – 对象
- Return type:
- call(arg__1, arg__2, arg__3, arg__4, arg__5, arg__6, arg__7, arg__8)
- Parameters:
arg__1 –
CallMode
arg__2 – 字符串
arg__3 – 对象
arg__4 – 对象
arg__5 – 对象
arg__6 – 对象
arg__7 – 对象
arg__8 – 对象
- Return type:
- call(arg__1, arg__2, arg__3, arg__4, arg__5, arg__6, arg__7, arg__8, arg__9)
- Parameters:
arg__1 –
CallMode
arg__2 – 字符串
arg__3 – 对象
arg__4 – 对象
arg__5 – 对象
arg__6 – 对象
arg__7 – 对象
arg__8 – 对象
arg__9 – 对象
- Return type:
- call(arg__1, arg__2, arg__3, arg__4, arg__5, arg__6, arg__7, arg__8, arg__9, arg__10)
- Parameters:
arg__1 –
CallMode
arg__2 – 字符串
arg__3 – 对象
arg__4 – 对象
arg__5 – 对象
arg__6 – 对象
arg__7 – 对象
arg__8 – 对象
arg__9 – 对象
arg__10 – 对象
- Return type:
- callWithArgumentList(mode, method, args)¶
- Parameters:
mode –
CallMode
method – str
args – QVariant 的列表
- Return type:
调用此接口上由
method
指定的远程方法,使用args
作为参数。此函数返回作为回复接收到的消息,可以是正常的ReplyMessage
(表示成功)或ErrorMessage
(如果调用失败)。mode
参数指定了此调用的方式。如果调用成功,
lastError()
将被清除;否则,它将包含此调用产生的错误。通常,你应该使用
call()
来进行调用。警告
如果你使用
UseEventLoop
,你的代码必须准备好处理任何重入:其他方法调用和信号可能在此函数返回之前传递,以及其他Qt排队的信号和事件。- callWithCallback(method, args, receiver, member)¶
- Parameters:
method – str
args – QVariant 的列表
receiver –
QObject
member – str
- Return type:
布尔
这是一个重载函数。
此函数已弃用。请使用重载版本。
调用此接口上由
method
指定的远程方法,使用args
作为参数。此函数在排队调用后立即返回。来自远程函数的回复或由其发出的任何错误将传递到对象receiver
上的slot
槽。如果排队成功,此函数返回
true
:这并不表示调用成功。如果失败,将调用带有错误消息的插槽。在这些情况下,lastError()
将不会被设置。另请参阅
- callWithCallback(method, args, receiver, member, errorSlot)
- Parameters:
method – str
args – QVariant 的列表
receiver –
QObject
member – str
errorSlot – str
- Return type:
布尔
调用此接口上由
method
指定的远程方法,使用args
作为参数。此函数在排队调用后立即返回。远程函数的回复将传递给对象receiver
上的returnMethod
。如果发生错误,则调用对象receiver
上的errorMethod
。如果排队成功,此函数返回
true
。它并不表示执行的调用成功。如果失败,将调用errorMethod
。如果排队失败,此函数返回false
,并且不会调用任何插槽。returnMethod
的参数必须是函数调用返回的类型。可选地,它可以有一个QDBusMessage
参数作为其最后一个或唯一的参数。errorMethod
必须有一个QDBusError
作为其唯一的参数。- connection()¶
- Return type:
返回此接口关联的连接。
- interface()¶
- Return type:
字符串
返回此接口的名称。
- internalConstCall(mode, method[, args=list()])¶
- Parameters:
mode –
CallMode
method – str
args – QVariant 的列表
- Return type:
- internalPropGet(propname)¶
- Parameters:
propname – str
- Return type:
对象
- internalPropSet(propname, value)¶
- Parameters:
propname – str
value – 对象
- isInteractiveAuthorizationAllowed()¶
- Return type:
布尔
返回调用者是否准备等待交互式授权,用于异步调用。
默认是
false
。- isValid()¶
- Return type:
布尔
如果这是对远程对象的有效引用,则返回
true
。如果在创建此接口时发生错误(例如,如果远程应用程序不存在),则返回false
。注意:在处理远程对象时,创建
QDBusInterface
时并不总是能够确定它是否存在。- lastError()¶
- Return type:
返回上次操作产生的错误,如果上次操作没有产生错误,则返回无效错误。
- path()¶
- Return type:
字符串
返回与此接口关联的对象路径。
- service()¶
- Return type:
字符串
返回此接口关联的服务的名称。
- setInteractiveAuthorizationAllowed(enable)¶
- Parameters:
enable – 布尔值
配置是否,对于异步调用,调用者准备等待交互式授权。
如果
enable
设置为true
,通过此接口生成的用于异步调用的 D-Bus 消息将设置ALLOW_INTERACTIVE_AUTHORIZATION
标志。此标志仅在非特权代码调用更高特权的方法调用时有用,并且部署了可能允许交互式授权的授权框架。
默认是
false
。- setTimeout(timeout)¶
- Parameters:
timeout – int
设置所有未来DBus调用的超时时间为
timeout
毫秒。-1表示使用默认的DBus超时时间(通常为25秒)。另请参阅
- timeout()¶
- Return type:
整数
返回当前超时值,单位为毫秒。-1 表示默认的 DBus 超时(通常为 25 秒)。
另请参阅