Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
QDBusPendingReply< Types > Class Template Reference

\inmodule QtDBus More...

#include <qdbuspendingreply.h>

+ Inheritance diagram for QDBusPendingReply< Types >:
+ Collaboration diagram for QDBusPendingReply< Types >:

Public Types

enum  { Count = std::is_same_v<typename Select<0>::Type, void> ? 0 : sizeof...(Types) }
 

Public Member Functions

constexpr int count () const
 Return the number of arguments the reply is supposed to have.
 
 QDBusPendingReply ()=default
 Creates an empty QDBusPendingReply object.
 
 QDBusPendingReply (const QDBusPendingReply &other)
 Creates a copy of the other QDBusPendingReply object.
 
Q_IMPLICIT QDBusPendingReply (const QDBusPendingCall &call)
 Creates a QDBusPendingReply object that will take its contents from the call pending asynchronous call.
 
Q_IMPLICIT QDBusPendingReply (const QDBusMessage &message)
 Creates a QDBusPendingReply object that will take its contents from the message message.
 
QDBusPendingReplyoperator= (const QDBusPendingReply &other)
 Makes a copy of other and drops the reference to the current pending call.
 
QDBusPendingReplyoperator= (const QDBusPendingCall &call)
 Makes this object take its contents from the call pending call and drops the reference to the current pending call.
 
QDBusPendingReplyoperator= (const QDBusMessage &message)
 Makes this object take its contents from the message message and drops the reference to the current pending call.
 
template<int Index>
Select< Index >::Type argumentAt () const
 Returns the argument at position index in the reply's contents.
 
Select< 0 >::Type value () const
 Returns the first argument in this reply, cast to type Types[0] (the first template parameter of this class).
 
 operator typename Select< 0 >::Type () const
 Returns the first argument in this reply, cast to type Types[0] (the first template parameter of this class).
 
QVariant argumentAt (int index) const
 
- Public Member Functions inherited from QDBusPendingCall
 QDBusPendingCall (const QDBusPendingCall &other)
 Creates a copy of the other pending asynchronous call.
 
 ~QDBusPendingCall ()
 Destroys this copy of the QDBusPendingCall object.
 
QDBusPendingCalloperator= (QDBusPendingCall &&other) noexcept
 
QDBusPendingCalloperator= (const QDBusPendingCall &other)
 Creates a copy of the other pending asynchronous call and drops the reference to the previously-referenced call.
 
void swap (QDBusPendingCall &other) noexcept
 
bool isFinished () const
 
void waitForFinished ()
 
bool isError () const
 
bool isValid () const
 
QDBusError error () const
 
QDBusMessage reply () const
 

Additional Inherited Members

- Static Public Member Functions inherited from QDBusPendingCall
static QDBusPendingCall fromError (const QDBusError &error)
 
static QDBusPendingCall fromCompletedCall (const QDBusMessage &message)
 
- Protected Member Functions inherited from QDBusPendingReplyBase
 QDBusPendingReplyBase ()
 
 ~QDBusPendingReplyBase ()
 
void assign (const QDBusPendingCall &call)
 
void assign (const QDBusMessage &message)
 
QVariant argumentAt (int index) const
 
void setMetaTypes (int count, const QMetaType *metaTypes)
 
- Protected Member Functions inherited from QDBusPendingCall
 QDBusPendingCall (QDBusPendingCallPrivate *dd)
 
- Protected Attributes inherited from QDBusPendingCall
QExplicitlySharedDataPointer< QDBusPendingCallPrivated
 

Detailed Description

template<typename... Types>
class QDBusPendingReply< Types >

\inmodule QtDBus

Since
4.5

The QDBusPendingReply class contains the reply to an asynchronous method call.

The QDBusPendingReply is a variadic template class. The template parameters are the types that will be used to extract the contents of the reply's data.

This class is similar in functionality to QDBusReply, but with two important differences:

\list

Where with QDBusReply you would write:

QDBusReply<QString> reply = interface->call("RemoteMethod");
if (reply.isValid())
// use the returned value
useValue(reply.value());
else
// call failed. Show an error condition.

with QDBusPendingReply, the equivalent code (including the blocking wait for the reply) would be:

QDBusPendingReply<QString> reply = iface->asyncCall("RemoteMethod");
reply.waitForFinished();
if (reply.isError())
// call failed. Show an error condition.
else
// use the returned value
useValue(reply.value());

For method calls that have more than one output argument, with QDBusReply, you would write:

whereas with QDBusPendingReply, all of the output arguments should be template parameters:

QDBusPendingReply<bool, QString> reply = iface->asyncCall("RemoteMethod");
reply.waitForFinished();
if (!reply.isError()) {
if (reply.argumentAt<0>())
showSuccess(reply.argumentAt<1>());
else
showFailure(reply.argumentAt<1>());
}

QDBusPendingReply objects can be associated with QDBusPendingCallWatcher objects, which emit signals when the reply arrives.

See also
QDBusPendingCallWatcher, QDBusReply

Definition at line 50 of file qdbuspendingreply.h.

Member Enumeration Documentation

◆ anonymous enum

template<typename... Types>
anonymous enum
Enumerator
Count 

Definition at line 54 of file qdbuspendingreply.h.

Constructor & Destructor Documentation

◆ QDBusPendingReply() [1/4]

template<typename... Types>
template< typename... Types > QDBusPendingReply< Types >::QDBusPendingReply ( )
inlinedefault

Creates an empty QDBusPendingReply object.

Without assigning a QDBusPendingCall object to this reply, QDBusPendingReply cannot do anything. All functions return their failure values.

◆ QDBusPendingReply() [2/4]

template<typename... Types>
template< typename... Types > QDBusPendingReply< Types >::QDBusPendingReply ( const QDBusPendingReply< Types > & other)
inline

Creates a copy of the other QDBusPendingReply object.

Just like QDBusPendingCall and QDBusPendingCallWatcher, this QDBusPendingReply object will share the same pending call reference. All copies share the same return values.

Definition at line 60 of file qdbuspendingreply.h.

◆ QDBusPendingReply() [3/4]

template<typename... Types>
template< typename... Types > QDBusPendingReply< Types >::QDBusPendingReply ( const QDBusPendingCall & call)
inline

Creates a QDBusPendingReply object that will take its contents from the call pending asynchronous call.

This QDBusPendingReply object will share the same pending call reference as call.

Definition at line 63 of file qdbuspendingreply.h.

◆ QDBusPendingReply() [4/4]

template<typename... Types>
template< typename... Types > QDBusPendingReply< Types >::QDBusPendingReply ( const QDBusMessage & message)
inline

Creates a QDBusPendingReply object that will take its contents from the message message.

In this case, this object will be already in its finished state and the reply's contents will be accessible.

See also
isFinished()

Definition at line 65 of file qdbuspendingreply.h.

Member Function Documentation

◆ argumentAt() [1/2]

template<typename... Types>
template<int Index>
template< typename... Types > QVariant QDBusPendingReply< Types >::argumentAt ( ) const
inline

Returns the argument at position index in the reply's contents.

If the reply doesn't have that many elements, this function's return value is undefined (will probably cause an assertion failure), so it is important to verify that the processing is finished and the reply is valid.

If the reply does not contain an argument at position index or if the reply was an error, this function returns an invalid QVariant. Since D-Bus messages can never contain invalid QVariants, this return can be used to detect an error condition.

Definition at line 77 of file qdbuspendingreply.h.

References QDBusPendingReply< Types >::argumentAt(), and QDBusPendingReply< Types >::Count.

Referenced by QDBusPendingReply< Types >::argumentAt().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ argumentAt() [2/2]

template<typename... Types>
QVariant QDBusPendingReplyBase::argumentAt ( int index) const

Definition at line 24 of file qdbuspendingreply.cpp.

◆ count()

template<typename... Types>
template< typename... Types > int QDBusPendingReply< Types >::count ( ) const
inlineconstexpr

Return the number of arguments the reply is supposed to have.

This number matches the number of non-void template parameters in this class.

If the reply arrives with a different number of arguments (or with different types), it will be transformed into an error reply indicating a bad signature.

Definition at line 56 of file qdbuspendingreply.h.

References QDBusPendingReply< Types >::Count.

◆ operator typename Select< 0 >::Type()

template<typename... Types>
template< typename... Types > QDBusPendingReply< Types >::operator typename Select< 0 >::Type ( ) const
inline

Returns the first argument in this reply, cast to type Types[0] (the first template parameter of this class).

This is equivalent to calling argumentAt<0>().

This function is provided as a convenience, matching the QDBusReply::value() function.

Note that, if the reply hasn't arrived, this function causes the calling thread to block until the reply is processed.

If the reply is an error reply, this function returns a default-constructed Types[0] object, which may be indistinguishable from a valid value. To reliably determine whether the message was an error, use isError().

Definition at line 100 of file qdbuspendingreply.h.

◆ operator=() [1/3]

template<typename... Types>
template< typename... Types > QDBusPendingReply & QDBusPendingReply< Types >::operator= ( const QDBusMessage & message)
inline

Makes this object take its contents from the message message and drops the reference to the current pending call.

If the current reference is to an unfinished pending call and this is the last reference, the pending call will be canceled and there will be no way of retrieving the reply's contents, when they arrive.

After this function is finished, the QDBusPendingReply object will be in its "finished" state and the message contents will be accessible.

See also
isFinished()

Definition at line 72 of file qdbuspendingreply.h.

◆ operator=() [2/3]

template<typename... Types>
template< typename... Types > QDBusPendingReply & QDBusPendingReply< Types >::operator= ( const QDBusPendingCall & call)
inline

Makes this object take its contents from the call pending call and drops the reference to the current pending call.

If the current reference is to an unfinished pending call and this is the last reference, the pending call will be canceled and there will be no way of retrieving the reply's contents, when they arrive.

Definition at line 70 of file qdbuspendingreply.h.

◆ operator=() [3/3]

template<typename... Types>
template< typename... Types > QDBusPendingReply & QDBusPendingReply< Types >::operator= ( const QDBusPendingReply< Types > & other)
inline

Makes a copy of other and drops the reference to the current pending call.

If the current reference is to an unfinished pending call and this is the last reference, the pending call will be canceled and there will be no way of retrieving the reply's contents, when they arrive.

Definition at line 68 of file qdbuspendingreply.h.

References other().

+ Here is the call graph for this function:

◆ value()

template<typename... Types>
template< typename... Types > typename Select< 0 >::Type QDBusPendingReply< Types >::value ( ) const
inline

Returns the first argument in this reply, cast to type Types[0] (the first template parameter of this class).

This is equivalent to calling argumentAt<0>().

This function is provided as a convenience, matching the QDBusReply::value() function.

Note that, if the reply hasn't arrived, this function causes the calling thread to block until the reply is processed.

If the reply is an error reply, this function returns a default-constructed Types[0] object, which may be indistinguishable from a valid value. To reliably determine whether the message was an error, use isError().

Definition at line 95 of file qdbuspendingreply.h.


The documentation for this class was generated from the following files: