class QDBusArgument#

The QDBusArgument class is used to marshall and demarshall D-Bus arguments. More

Synopsis#

Methods#

Note

This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE

Detailed Description#

Warning

This section contains snippets that were automatically translated from C++ to Python and may contain errors.

The class is used to send arguments over D-Bus to remote applications and to receive them back. D-Bus offers an extensible type system, based on a few primitive types and associations of them. See the Qt D-Bus Type System page for more information on the type system.

QDBusArgument is the central class in the Qt D-Bus type system, providing functions to marshall and demarshall the primitive types. The compound types are then created by association of one or more of the primitive types in arrays, dictionaries or structures.

The following example illustrates how a structure containing an integer and a string can be constructed using the Qt D-Bus type system :

class MyStructure():

    count = int()
    name = QString()

    # ...

Q_DECLARE_METATYPE(MyStructure)
# Marshall the MyStructure data into a D-Bus argument
QDBusArgument operator<<(QDBusArgument argument, MyStructure myStruct)

    argument.beginStructure()
    argument << myStruct.count << myStruct.name
    argument.endStructure()
    return argument

# Retrieve the MyStructure data from the D-Bus argument
QDBusArgument operator>>(QDBusArgument argument, MyStructure myStruct)

    argument.beginStructure()
    argument >> myStruct.count >> myStruct.name
    argument.endStructure()
    return argument

The type has to be registered with qDBusRegisterMetaType() before it can be used with QDBusArgument . Therefore, somewhere in your program, you should add the following code:

qDBusRegisterMetaType<MyStructure>()

Once registered, a type can be used in outgoing method calls (placed with call() ), signal emissions from registered objects or in incoming calls from remote applications.

It is important to note that the operator<< and operator>> streaming functions must always produce the same number of entries in case of structures, both in reading and in writing (marshalling and demarshalling), otherwise calls and signals may start to silently fail.

The following example illustrates this wrong usage in context of a class that may contain invalid data:

//bad code
    // Wrongly marshall the MyTime data into a D-Bus argument
    QDBusArgument &operator<<(QDBusArgument &argument, const MyTime &mytime)
    {
        argument.beginStructure();
        if (mytime.isValid)
            argument << true << mytime.hour
                     << mytime.minute << mytime.second;
        else
            argument << false;
        argument.endStructure();
        return argument;
    }

In this example, both the operator<< and the operator>> functions may produce a different number of reads/writes. This can confuse the Qt D-Bus type system and should be avoided.

class ElementType#

This enum describes the type of element held by the argument.

Constant

Description

QDBusArgument.BasicType

A basic element, which is understood by QVariant. The following types are considered basic: bool, byte, short, ushort, int, uint, qint64, quint64, double, QString, QByteArray, QDBusObjectPath , QDBusSignature

QDBusArgument.VariantType

The variant element ( QDBusVariant )

QDBusArgument.ArrayType

An array element, usually represented by QList<T>. Note: QByteArray and associative maps are not considered arrays, even if the D-Bus protocol transports them as such.

QDBusArgument.StructureType

A custom type represented by a structure, like QDateTime, QPoint, etc.

QDBusArgument.MapType

An associative container, like QMap<Key, Value> or QHash<Key, Value>

QDBusArgument.MapEntryType

One entry in an associative container: both the key and the value form one map-entry type.

QDBusArgument.UnknownType

The type is unknown or we have reached the end of the list.

See also

currentType()

__init__(other)#
Parameters:

otherQDBusArgument

Constructs a copy of the other QDBusArgument object.

Both objects will therefore contain the same state from this point forward. QDBusArguments are explicitly shared and, therefore, any modification to either copy will affect the other one too.

__init__()

Constructs an empty QDBusArgument argument.

An empty QDBusArgument object does not allow either reading or writing to be performed.

appendVariant(v)#
Parameters:

v – object

asVariant()#
Return type:

object

Returns the current argument in the form of a QVariant. Basic types will be decoded and returned in the QVariant, but for complex types, this function will return a QDBusArgument object in the QVariant. It is the caller’s responsibility to decode the argument (for example, by calling asVariant() in it).

For example, if the current argument is an INT32, this function will return a QVariant with an argument of type QMetaType::Int. For an array of INT32, it will return a QVariant containing a QDBusArgument .

If an error occurs or if there are no more arguments to decode (i.e., we are at the end of the argument list), this function will return an invalid QVariant.

See also

atEnd()

atEnd()#
Return type:

bool

Returns true if there are no more elements to be extracted from this QDBusArgument . This function is usually used in QDBusArgument objects returned from beginMap() and beginArray() .

beginArray()#

Warning

This section contains snippets that were automatically translated from C++ to Python and may contain errors.

Recurses into the D-Bus array to allow extraction of the array elements.

This function is used usually in operator>> streaming operators, as in the following example:

# Extract a MyArray array of MyElement elements
QDBusArgument operator>>(QDBusArgument argument, MyArray myArray)

    argument.beginArray()
    myArray.clear()
    while not argument.atEnd():
        element = MyElement()
        argument >> element
        myArray.append(element)

    argument.endArray()
    return argument

If the type you want to demarshall is a QList or any of the Qt’s Container Classes that take one template parameter, you need not declare an operator>> function for it, since Qt D-Bus provides generic templates to do the job of demarshalling the data. The same applies for STL’s sequence containers, such as std::list, std::vector, etc.

beginArray(elementMetaType)
Parameters:

elementMetaTypeQMetaType

Warning

This section contains snippets that were automatically translated from C++ to Python and may contain errors.

Opens a new D-Bus array suitable for appending elements of meta-type id.

This function is used usually in operator<< streaming operators, as in the following example:

# Append an array of MyElement types
QDBusArgument operator<<(QDBusArgument argument, MyArray myArray)

    argument.beginArray(qMetaTypeId<MyElement>())
    for element in myArray:
        argument << element
    argument.endArray()
    return argument

If the type you want to marshall is a QList or any of the Qt’s Container Classes that take one template parameter, you need not declare an operator<< function for it, since Qt D-Bus provides generic templates to do the job of marshalling the data. The same applies for STL’s sequence containers, such as std::list, std::vector, etc.

beginArray(elementMetaTypeId)
Parameters:

elementMetaTypeId – int

Warning

This section contains snippets that were automatically translated from C++ to Python and may contain errors.

Opens a new D-Bus array suitable for appending elements of meta-type id.

This function is used usually in operator<< streaming operators, as in the following example:

# Append an array of MyElement types
QDBusArgument operator<<(QDBusArgument argument, MyArray myArray)

    argument.beginArray(qMetaTypeId<MyElement>())
    for element in myArray:
        argument << element
    argument.endArray()
    return argument

If the type you want to marshall is a QList or any of the Qt’s Container Classes that take one template parameter, you need not declare an operator<< function for it, since Qt D-Bus provides generic templates to do the job of marshalling the data. The same applies for STL’s sequence containers, such as std::list, std::vector, etc.

beginMap()#

Warning

This section contains snippets that were automatically translated from C++ to Python and may contain errors.

Recurses into the D-Bus map to allow extraction of the map’s elements.

This function is used usually in operator>> streaming operators, as in the following example:

# Extract a MyDictionary map that associates integers to MyElement items
QDBusArgument operator>>(QDBusArgument argument, MyDictionary myDict)

    argument.beginMap()
    myDict.clear()
    while not argument.atEnd():
        key = int()
        value = MyElement()
        argument.beginMapEntry()
        argument >> key >> value
        argument.endMapEntry()
        myDict.insert(key, value)

    argument.endMap()
    return argument

If the type you want to demarshall is a QMap or QHash, you need not declare an operator>> function for it, since Qt D-Bus provides generic templates to do the job of demarshalling the data.

beginMap(keyMetaType, valueMetaType)
Parameters:

Warning

This section contains snippets that were automatically translated from C++ to Python and may contain errors.

Opens a new D-Bus map suitable for appending elements. Maps are containers that associate one entry (the key) to another (the value), such as Qt’s QMap or QHash. The ids of the map’s key and value meta types must be passed in keyMetaType and valueMetaType respectively.

This function is used usually in operator<< streaming operators, as in the following example:

# Append a dictionary that associates ints to MyValue types
QDBusArgument operator<<(QDBusArgument argument, MyDictionary myDict)

    argument.beginMap(QMetaType.fromType<int>(), QMetaType.fromType<MyValue>())
    MyDictionary.const_iterator i
    for i in myDict:
        argument.beginMapEntry()
        argument << i.key() << i.value()
        argument.endMapEntry()

    argument.endMap()
    return argument

You usually don’t need to provide an operator<< or operator>> function for associative containers such as QHash or std::map, since Qt D-Bus provides generic templates to do the job of marshalling the data.

beginMap(keyMetaTypeId, valueMetaTypeId)
Parameters:
  • keyMetaTypeId – int

  • valueMetaTypeId – int

Warning

This section contains snippets that were automatically translated from C++ to Python and may contain errors.

Opens a new D-Bus map suitable for appending elements. Maps are containers that associate one entry (the key) to another (the value), such as Qt’s QMap or QHash. The ids of the map’s key and value meta types must be passed in keyMetaType and valueMetaType respectively.

This function is used usually in operator<< streaming operators, as in the following example:

# Append a dictionary that associates ints to MyValue types
QDBusArgument operator<<(QDBusArgument argument, MyDictionary myDict)

    argument.beginMap(QMetaType.fromType<int>(), QMetaType.fromType<MyValue>())
    MyDictionary.const_iterator i
    for i in myDict:
        argument.beginMapEntry()
        argument << i.key() << i.value()
        argument.endMapEntry()

    argument.endMap()
    return argument

You usually don’t need to provide an operator<< or operator>> function for associative containers such as QHash or std::map, since Qt D-Bus provides generic templates to do the job of marshalling the data.

beginMapEntry()#

Recurses into the D-Bus map entry to allow extraction of the key and value pair.

See beginMap() for an example of how this function is usually used.

beginStructure()#

Warning

This section contains snippets that were automatically translated from C++ to Python and may contain errors.

Opens a D-Bus structure suitable for extracting elements.

This function is used usually in operator>> streaming operators, as in the following example:

QDBusArgument operator>>(QDBusArgument argument, MyStructure myStruct)

    argument.beginStructure()
    argument >> myStruct.member1 >> myStruct.member2 >> myStruct.member3
    argument.endStructure()
    return argument
currentSignature()#
Return type:

str

currentType()#
Return type:

ElementType

Returns the classification of the current element type. If an error decoding the type occurs or if we’re at the end of the argument, this function returns UnknownType .

This function only makes sense when demarshalling arguments. If it is used while marshalling, it will always return UnknownType .

endArray()#

Closes the D-Bus array and allow extracting of the next element after the array.

See also

beginArray()

endMap()#

Closes the D-Bus map and allow extracting of the next element after the map.

See also

beginMap()

endMapEntry()#

Closes the D-Bus map entry and allow extracting of the next element on the map.

See also

beginMapEntry()

endStructure()#

Closes the D-Bus structure and allow extracting of the next element after the structure.

See also

beginStructure()

__lshift__(arg)#
Parameters:

arg – int

Return type:

QDBusArgument

This is an overloaded function.

Appends the primitive value arg of type UINT16 to the D-Bus stream.

__lshift__(arg)
Parameters:

arg – int

Return type:

QDBusArgument

This is an overloaded function.

Appends the primitive value arg of type UINT32 to the D-Bus stream.

__lshift__(arg)
Parameters:

arg – int

Return type:

QDBusArgument

Appends the primitive value arg of type BYTE to the D-Bus stream.

__lshift__(arg)
Parameters:

arg – int

Return type:

QDBusArgument

This is an overloaded function.

Appends the primitive value arg of type INT16 to the D-Bus stream.

__lshift__(arg)
Parameters:

arg – int

Return type:

QDBusArgument

This is an overloaded function.

Appends the primitive value arg of type UINT64 to the D-Bus stream.

__lshift__(arg)
Parameters:

arg – int

Return type:

QDBusArgument

This is an overloaded function.

Appends the primitive value arg of type INT64 to the D-Bus stream.

__lshift__(arg)
Parameters:

arg – int

Return type:

QDBusArgument

This is an overloaded function.

Appends the primitive value arg of type INT32 to the D-Bus stream.

__lshift__(arg)
Parameters:

arg – float

Return type:

QDBusArgument

This is an overloaded function.

Appends the primitive value arg of type DOUBLE (double-precision floating-point) to the D-Bus stream.

__lshift__(time)
Parameters:

timeQTime

Return type:

QDBusArgument

__lshift__(arg)
Parameters:

arg – list of strings

Return type:

QDBusArgument

This is an overloaded function.

Appends the QStringList given by arg as ARRAY of STRING to the D-Bus stream.

QStringList and QByteArray are the only two non-primitive types that are supported directly by QDBusArgument because of their widespread usage in Qt applications.

Other arrays are supported through compound types in Qt D-Bus.

__lshift__(arg)
Parameters:

arg – str

Return type:

QDBusArgument

This is an overloaded function.

Appends the primitive value arg of type STRING (Unicode character string) to the D-Bus stream.

__lshift__(size)
Parameters:

sizeQSizeF

Return type:

QDBusArgument

__lshift__(size)
Parameters:

sizeQSize

Return type:

QDBusArgument

__lshift__(rect)
Parameters:

rectQRectF

Return type:

QDBusArgument

__lshift__(rect)
Parameters:

rectQRect

Return type:

QDBusArgument

__lshift__(pt)
Parameters:

ptQPoint

Return type:

QDBusArgument

__lshift__(pt)
Parameters:

ptQPointF

Return type:

QDBusArgument

__lshift__(arg)
Parameters:

arg – bool

Return type:

QDBusArgument

This is an overloaded function.

Appends the primitive value arg of type BOOLEAN to the D-Bus stream.

__lshift__(arg)
Parameters:

argQByteArray

Return type:

QDBusArgument

This is an overloaded function.

Appends the QByteArray given by arg as ARRAY of BYTE to the D-Bus stream.

QStringList and QByteArray are the only two non-primitive types that are supported directly by QDBusArgument because of their widespread usage in Qt applications.

Other arrays are supported through compound types in Qt D-Bus.

__lshift__(arg)
Parameters:

argQDBusObjectPath

Return type:

QDBusArgument

__lshift__(arg)
Parameters:

argQDBusSignature

Return type:

QDBusArgument

__lshift__(arg)
Parameters:

argQDBusUnixFileDescriptor

Return type:

QDBusArgument

__lshift__(arg)
Parameters:

argQDBusVariant

Return type:

QDBusArgument

This is an overloaded function.

Appends the primitive value arg of type VARIANT to the D-Bus stream.

A D-Bus variant type can contain any type, including other variants. It is similar to the Qt QVariant type.

__lshift__(dt)
Parameters:

dtQDateTime

Return type:

QDBusArgument

__lshift__(map)
Parameters:

map – Dictionary with keys of type .QString and values of type QVariant.

Return type:

QDBusArgument

__lshift__(line)
Parameters:

lineQLine

Return type:

QDBusArgument

__lshift__(line)
Parameters:

lineQLineF

Return type:

QDBusArgument

__lshift__(list)
Parameters:

list – .list of QVariant

Return type:

QDBusArgument

__lshift__(map)
Parameters:

map – Dictionary with keys of type .QString and values of type QVariant.

Return type:

QDBusArgument

__lshift__(date)
Parameters:

dateQDate

Return type:

QDBusArgument

__rshift__(arg)#
Parameters:

arg – str

Return type:

QDBusArgument

This is an overloaded function.

Extracts one D-Bus primitive argument of type STRING (Unicode character string) from the D-Bus stream.

__rshift__(arg)
Parameters:

arg – list of strings

Return type:

QDBusArgument

This is an overloaded function.

Extracts an array of strings from the D-Bus stream and return it as a QStringList.

QStringList and QByteArray are the only two non-primitive types that are supported directly by QDBusArgument because of their widespread usage in Qt applications.

Other arrays are supported through compound types in Qt D-Bus.

__rshift__(time)
Parameters:

timeQTime

Return type:

QDBusArgument

__rshift__(v)
Parameters:

v – object

Return type:

QDBusArgument

__rshift__(arg)
Parameters:

arg – bool

Return type:

QDBusArgument

This is an overloaded function.

Extracts one D-Bus primitive argument of type BOOLEAN from the D-Bus stream.

__rshift__(arg)
Parameters:

argdouble

Return type:

QDBusArgument

This is an overloaded function.

Extracts one D-Bus primitive argument of type DOUBLE (double-precision floating point) from the D-Bus stream.

__rshift__(line)
Parameters:

lineQLine

Return type:

QDBusArgument

__rshift__(arg)
Parameters:

arg – int

Return type:

QDBusArgument

This is an overloaded function.

Extracts one D-Bus primitive argument of type INT32 from the D-Bus stream.

__rshift__(arg)
Parameters:

argqlonglong

Return type:

QDBusArgument

This is an overloaded function.

Extracts one D-Bus primitive argument of type INT64 from the D-Bus stream.

__rshift__(arg)
Parameters:

argqulonglong

Return type:

QDBusArgument

This is an overloaded function.

Extracts one D-Bus primitive argument of type UINT64 from the D-Bus stream.

__rshift__(arg)
Parameters:

argshort

Return type:

QDBusArgument

This is an overloaded function.

Extracts one D-Bus primitive argument of type INT16 from the D-Bus stream.

__rshift__(arg)
Parameters:

arg – str

Return type:

QDBusArgument

Extracts one D-Bus primitive argument of type BYTE from the D-Bus stream and puts it into arg.

__rshift__(arg)
Parameters:

arguint

Return type:

QDBusArgument

This is an overloaded function.

Extracts one D-Bus primitive argument of type UINT32 from the D-Bus stream.

__rshift__(arg)
Parameters:

argushort

Return type:

QDBusArgument

This is an overloaded function.

Extracts one D-Bus primitive argument of type UINT16 from the D-Bus stream.

__rshift__(size)
Parameters:

sizeQSizeF

Return type:

QDBusArgument

__rshift__(size)
Parameters:

sizeQSize

Return type:

QDBusArgument

__rshift__(rect)
Parameters:

rectQRectF

Return type:

QDBusArgument

__rshift__(rect)
Parameters:

rectQRect

Return type:

QDBusArgument

__rshift__(pt)
Parameters:

ptQPointF

Return type:

QDBusArgument

__rshift__(pt)
Parameters:

ptQPoint

Return type:

QDBusArgument

__rshift__(line)
Parameters:

lineQLineF

Return type:

QDBusArgument

__rshift__(dt)
Parameters:

dtQDateTime

Return type:

QDBusArgument

__rshift__(date)
Parameters:

dateQDate

Return type:

QDBusArgument

__rshift__(arg)
Parameters:

argQDBusVariant

Return type:

QDBusArgument

This is an overloaded function.

Extracts one D-Bus primitive argument of type VARIANT from the D-Bus stream.

A D-Bus variant type can contain any type, including other variants. It is similar to the Qt QVariant type.

In case the variant contains a type not directly supported by QDBusArgument , the value of the returned QDBusVariant will contain another QDBusArgument . It is your responsibility to further demarshall it into another type.

__rshift__(arg)
Parameters:

argQDBusUnixFileDescriptor

Return type:

QDBusArgument

__rshift__(arg)
Parameters:

argQDBusSignature

Return type:

QDBusArgument

__rshift__(arg)
Parameters:

argQDBusObjectPath

Return type:

QDBusArgument

__rshift__(arg)
Parameters:

argQByteArray

Return type:

QDBusArgument

This is an overloaded function.

Extracts an array of bytes from the D-Bus stream and return it as a QByteArray.

QStringList and QByteArray are the only two non-primitive types that are supported directly by QDBusArgument because of their widespread usage in Qt applications.

Other arrays are supported through compound types in Qt D-Bus.

swap(other)#
Parameters:

otherQDBusArgument

Swaps this QDBusArgument instance with other.