QDBusAbstractInterface 类是 Qt D-Bus 绑定中所有 D-Bus 接口的基类 (允许访问远程接口)。 更多...
头: | #include <QDBusAbstractInterface> |
CMake: |
find_package(Qt6 REQUIRED COMPONENTS DBus)
target_link_libraries(mytarget PRIVATE Qt6::DBus) |
qmake: | QT += dbus |
继承: | QObject |
继承者: |
virtual | ~QDBusAbstractInterface () |
QDBusPendingCall | asyncCall (const QString & method , Args &&... args ) |
QDBusPendingCall | asyncCallWithArgumentList (const QString & method , const QList<QVariant> & args ) |
QDBusMessage | call (const QString & method , Args &&... args ) |
QDBusMessage | call (QDBus::CallMode mode , const QString & method , Args &&... args ) |
QDBusMessage | callWithArgumentList (QDBus::CallMode mode , const QString & method , const QList<QVariant> & args ) |
bool | callWithCallback (const QString & method , const QList<QVariant> & args , QObject * receiver , const char * returnMethod , const char * errorMethod ) |
bool | callWithCallback (const QString & method , const QList<QVariant> & args , QObject * receiver , const char * slot ) |
QDBusConnection | connection () const |
QString | interface () const |
(从 6.7 起)
bool
|
isInteractiveAuthorizationAllowed () const |
bool | isValid () const |
QDBusError | lastError () const |
QString | path () const |
QString | service () const |
(从 6.7 起)
void
|
setInteractiveAuthorizationAllowed (bool enable ) |
void | setTimeout (int timeout ) |
int | timeout () const |
Generated-code classes also derive from QDBusAbstractInterface, all methods described here are also valid for generated-code classes. In addition to those described here, generated-code classes provide member functions for the remote methods, which allow for compile-time checking of the correct parameters and return values, as well as property type-matching and signal parameter-matching.
另请参阅 The QDBus compiler and QDBusInterface .
[virtual noexcept]
QDBusAbstractInterface::
~QDBusAbstractInterface
()
Releases this object's resources.
Calls the method method on this interface and passes args to the method. All args must be convertible to QVariant .
The parameters to
call
are passed on to the remote function via D-Bus as input arguments. The returned
QDBusPendingCall
object can be used to find out information about the reply.
It can be used the following way:
QDBusPendingCall pcall = interface->asyncCall("GetAPIVersion"_L1); auto watcher = new QDBusPendingCallWatcher(pcall, this); QObject::connect(watcher, &QDBusPendingCallWatcher::finished, this, [&](QDBusPendingCallWatcher *w) { QString value = retrieveValue(); QDBusPendingReply<int> reply(*w); QDBusPendingCall pcall; if (reply.argumentAt<0>() >= 14) pcall = interface->asyncCall("ProcessWorkUnicode"_L1, value); else pcall = interface->asyncCall("ProcessWork"_L1, "UTF-8"_L1, value.toUtf8()); w = new QDBusPendingCallWatcher(pcall); QObject::connect(w, &QDBusPendingCallWatcher::finished, this, &Abstract_DBus_Interface::callFinishedSlot); });
This example illustrates function calling with 0, 1 and 2 parameters and illustrates different parameter types passed in each (the first call to
"ProcessWorkUnicode"
will contain one Unicode string, the second call to
"ProcessWork"
will contain one string and one byte array). See
call
() for the same example in blocking (synchronous) calls.
注意: Before Qt 5.14, this function accepted a maximum of just eight (8) arguments.
注意:
Method calls to local
QDBusServer
's are never asynchronous due to implementation limitations.
另请参阅 asyncCallWithArgumentList ().
Places a call to the remote method specified by method on this interface, using args as arguments. This function returns a QDBusPendingCall object that can be used to track the status of the reply and access its contents once it has arrived.
Normally, you should place calls using asyncCall ().
注意: Method calls to objects registered by the application itself are never asynchronous due to implementation limitations.
注意: 此函数是 thread-safe .
Calls the method method on this interface and passes args to the method. All args must be convertible to QVariant .
The parameters to
call
are passed on to the remote function via D-Bus as input arguments. Output arguments are returned in the
QDBusMessage
reply. If the reply is an error reply,
lastError
() will also be set to the contents of the error message.
It can be used the following way:
QString value = retrieveValue(); QDBusMessage reply; QDBusReply<int> api = interface->call("GetAPIVersion"_L1); if (api >= 14) reply = interface->call("ProcessWorkUnicode"_L1, value); else reply = interface->call("ProcessWork"_L1, "UTF-8"_L1, value.toUtf8());
This example illustrates function calling with 0, 1 and 2 parameters and illustrates different parameter types passed in each (the first call to
"ProcessWorkUnicode"
will contain one Unicode string, the second call to
"ProcessWork"
will contain one string and one byte array). See
asyncCall
() for the same example in non-blocking (asynchronous) calls.
注意: Before Qt 5.14, this function accepted a maximum of just eight (8) arguments.
另请参阅 callWithArgumentList ().
这是重载函数。
Calls the method method on this interface and passes args to the method. All args must be convertible to QVariant .
若
mode
is
NoWaitForReply
, then this function will return immediately after placing the call, without waiting for a reply from the remote method. Otherwise,
mode
indicates whether this function should activate the Qt Event Loop while waiting for the reply to arrive.
If this function reenters the Qt event loop in order to wait for the reply, it will exclude user input. During the wait, it may deliver signals and other method calls to your application. Therefore, it must be prepared to handle a reentrancy whenever a call is placed with call().
注意: Before Qt 5.14, this function accepted a maximum of just eight (8) arguments.
另请参阅 callWithArgumentList ().
Places a call to the remote method specified by method on this interface, using args as arguments. This function returns the message that was received as a reply, which can be a normal QDBusMessage::ReplyMessage (indicating success) or QDBusMessage::ErrorMessage (if the call failed). The mode parameter specifies how this call should be placed.
If the call succeeds, lastError () will be cleared; otherwise, it will contain the error this call produced.
Normally, you should place calls using call ().
警告:
若使用
UseEventLoop
, your code must be prepared to deal with any reentrancy: other method calls and signals may be delivered before this function returns, as well as other Qt queued signals and events.
注意: 此函数是 thread-safe .
Places a call to the remote method specified by method on this interface, using args as arguments. This function returns immediately after queueing the call. The reply from the remote function is delivered to the returnMethod on object receiver . If an error occurs, the errorMethod on object receiver is called instead.
此函数返回
true
if the queueing succeeds. It does not indicate that the executed call succeeded. If it fails, the
errorMethod
is called. If the queueing failed, this function returns
false
and no slot will be called.
The returnMethod must have as its parameters the types returned by the function call. Optionally, it may have a QDBusMessage parameter as its last or only parameter. The errorMethod 必须拥有 QDBusError as its only parameter.
注意: Method calls to objects registered by the application itself are never asynchronous due to implementation limitations.
另请参阅 QDBusError and QDBusMessage .
这是重载函数。
This function is deprecated. Please use the overloaded version.
Places a call to the remote method specified by method on this interface, using args as arguments. This function returns immediately after queueing the call. The reply from the remote function or any errors emitted by it are delivered to the slot slot on object receiver .
此函数返回
true
if the queueing succeeded: it does not indicate that the call succeeded. If it failed, the slot will be called with an error message.
lastError
() will not be set under those circumstances.
另请参阅 QDBusError and QDBusMessage .
Returns the connection this interface is associated with.
Returns the name of this interface.
[since 6.7]
bool
QDBusAbstractInterface::
isInteractiveAuthorizationAllowed
() const
Returns whether, for asynchronous calls, the caller is prepared to wait for interactive authorization.
默认为
false
.
该函数在 Qt 6.7 引入。
另请参阅 setInteractiveAuthorizationAllowed () 和 QDBusMessage::setInteractiveAuthorizationAllowed ().
返回
true
if this is a valid reference to a remote object. It returns
false
if there was an error during the creation of this interface (for instance, if the remote application does not exist).
Note: when dealing with remote objects, it is not always possible to determine if it exists when creating a QDBusInterface .
Returns the error the last operation produced, or an invalid error if the last operation did not produce an error.
Returns the object path that this interface is associated with.
Returns the name of the service this interface is associated with.
[since 6.7]
void
QDBusAbstractInterface::
setInteractiveAuthorizationAllowed
(
bool
enable
)
Configures whether, for asynchronous calls, the caller is prepared to wait for interactive authorization.
若
enable
被设为
true
, the D-Bus messages generated for asynchronous calls via this interface will set the
ALLOW_INTERACTIVE_AUTHORIZATION
标志。
This flag is only useful when unprivileged code calls a more privileged method call, and an authorization framework is deployed that allows possibly interactive authorization.
默认为
false
.
该函数在 Qt 6.7 引入。
另请参阅 isInteractiveAuthorizationAllowed () 和 QDBusMessage::setInteractiveAuthorizationAllowed ().
Sets the timeout in milliseconds for all future DBus calls to timeout . -1 means the default DBus timeout (usually 25 seconds).
另请参阅 timeout ().
Returns the current value of the timeout in milliseconds. -1 means the default DBus timeout (usually 25 seconds).
另请参阅 setTimeout ().