QDBusArgument

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

Inheritance diagram of PySide6.QtDBus.QDBusArgument

Synopsis

Functions

Detailed Description

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
operator<< = QDBusArgument(QDBusArgument argument, MyStructure myStruct)

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

# Retrieve the MyStructure data from the D-Bus argument
operator>> = QDBusArgument(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.

See also

QDBusAbstractInterface The Qt D-Bus type system Using Adaptors qdbus_cast()

class PySide6.QtDBus.QDBusArgument

PySide6.QtDBus.QDBusArgument(other)

Parameters

otherPySide6.QtDBus.QDBusArgument

Constructs an empty QDBusArgument argument.

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

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.

PySide6.QtDBus.QDBusArgument.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()

PySide6.QtDBus.QDBusArgument.appendVariant(v)
Parameters

v – object

PySide6.QtDBus.QDBusArgument.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 in it).

For example, if the current argument is an INT32, this function will return a QVariant with an argument of type 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()

PySide6.QtDBus.QDBusArgument.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() .

PySide6.QtDBus.QDBusArgument.beginArray()

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
operator>> = QDBusArgument(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.

PySide6.QtDBus.QDBusArgument.beginArray(elementMetaType)
Parameters

elementMetaTypePySide6.QtCore.QMetaType

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
operator<< = QDBusArgument(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.

PySide6.QtDBus.QDBusArgument.beginArray(elementMetaTypeId)
Parameters

elementMetaTypeId – int

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
operator<< = QDBusArgument(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.

PySide6.QtDBus.QDBusArgument.beginMap(keyMetaTypeId, valueMetaTypeId)
Parameters
  • keyMetaTypeId – int

  • valueMetaTypeId – int

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
operator<< = QDBusArgument(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.

PySide6.QtDBus.QDBusArgument.beginMap(keyMetaType, valueMetaType)
Parameters

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
operator<< = QDBusArgument(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.

PySide6.QtDBus.QDBusArgument.beginMap()

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
operator>> = QDBusArgument(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.

PySide6.QtDBus.QDBusArgument.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.

PySide6.QtDBus.QDBusArgument.beginStructure()

Opens a D-Bus structure suitable for extracting elements.

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

operator>> = QDBusArgument(QDBusArgument argument, MyStructure myStruct)

    argument.beginStructure()
    argument >> myStruct.member1 >> myStruct.member2 >> myStruct.member3
    argument.endStructure()
    return argument
PySide6.QtDBus.QDBusArgument.currentSignature()
Return type

str

PySide6.QtDBus.QDBusArgument.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 .

PySide6.QtDBus.QDBusArgument.endArray()

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

See also

beginArray()

PySide6.QtDBus.QDBusArgument.endMap()

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

See also

beginMap()

PySide6.QtDBus.QDBusArgument.endMapEntry()

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

See also

beginMapEntry()

PySide6.QtDBus.QDBusArgument.endStructure()

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

See also

beginStructure()

PySide6.QtDBus.QDBusArgument.__lshift__(rect)
Parameters

rectPySide6.QtCore.QRect

Return type

PySide6.QtDBus.QDBusArgument

PySide6.QtDBus.QDBusArgument.__lshift__(rect)
Parameters

rectPySide6.QtCore.QRectF

Return type

PySide6.QtDBus.QDBusArgument

PySide6.QtDBus.QDBusArgument.__lshift__(size)
Parameters

sizePySide6.QtCore.QSize

Return type

PySide6.QtDBus.QDBusArgument

PySide6.QtDBus.QDBusArgument.__lshift__(size)
Parameters

sizePySide6.QtCore.QSizeF

Return type

PySide6.QtDBus.QDBusArgument

PySide6.QtDBus.QDBusArgument.__lshift__(arg)
Parameters

arg – str

Return type

PySide6.QtDBus.QDBusArgument

PySide6.QtDBus.QDBusArgument.__lshift__(arg)
Parameters

arg – list of strings

Return type

PySide6.QtDBus.QDBusArgument

PySide6.QtDBus.QDBusArgument.__lshift__(time)
Parameters

timePySide6.QtCore.QTime

Return type

PySide6.QtDBus.QDBusArgument

PySide6.QtDBus.QDBusArgument.__lshift__(arg)
Parameters

argdouble

Return type

PySide6.QtDBus.QDBusArgument

PySide6.QtDBus.QDBusArgument.__lshift__(arg)
Parameters

arg – int

Return type

PySide6.QtDBus.QDBusArgument

PySide6.QtDBus.QDBusArgument.__lshift__(arg)
Parameters

argqlonglong

Return type

PySide6.QtDBus.QDBusArgument

PySide6.QtDBus.QDBusArgument.__lshift__(arg)
Parameters

argqulonglong

Return type

PySide6.QtDBus.QDBusArgument

PySide6.QtDBus.QDBusArgument.__lshift__(arg)
Parameters

argshort

Return type

PySide6.QtDBus.QDBusArgument

PySide6.QtDBus.QDBusArgument.__lshift__(arg)
Parameters

arg – str

Return type

PySide6.QtDBus.QDBusArgument

PySide6.QtDBus.QDBusArgument.__lshift__(arg)
Parameters

arguint

Return type

PySide6.QtDBus.QDBusArgument

PySide6.QtDBus.QDBusArgument.__lshift__(arg)
Parameters

argushort

Return type

PySide6.QtDBus.QDBusArgument

PySide6.QtDBus.QDBusArgument.__lshift__(pt)
Parameters

ptPySide6.QtCore.QPoint

Return type

PySide6.QtDBus.QDBusArgument

PySide6.QtDBus.QDBusArgument.__lshift__(map)
Parameters

map

Return type

PySide6.QtDBus.QDBusArgument

PySide6.QtDBus.QDBusArgument.__lshift__(list)
Parameters

list

Return type

PySide6.QtDBus.QDBusArgument

PySide6.QtDBus.QDBusArgument.__lshift__(line)
Parameters

linePySide6.QtCore.QLineF

Return type

PySide6.QtDBus.QDBusArgument

PySide6.QtDBus.QDBusArgument.__lshift__(line)
Parameters

linePySide6.QtCore.QLine

Return type

PySide6.QtDBus.QDBusArgument

PySide6.QtDBus.QDBusArgument.__lshift__(map)
Parameters

map

Return type

PySide6.QtDBus.QDBusArgument

PySide6.QtDBus.QDBusArgument.__lshift__(dt)
Parameters

dtPySide6.QtCore.QDateTime

Return type

PySide6.QtDBus.QDBusArgument

PySide6.QtDBus.QDBusArgument.__lshift__(date)
Parameters

datePySide6.QtCore.QDate

Return type

PySide6.QtDBus.QDBusArgument

PySide6.QtDBus.QDBusArgument.__lshift__(arg)
Parameters

argPySide6.QtDBus.QDBusVariant

Return type

PySide6.QtDBus.QDBusArgument

PySide6.QtDBus.QDBusArgument.__lshift__(arg)
Parameters

argPySide6.QtDBus.QDBusUnixFileDescriptor

Return type

PySide6.QtDBus.QDBusArgument

PySide6.QtDBus.QDBusArgument.__lshift__(arg)
Parameters

argPySide6.QtDBus.QDBusSignature

Return type

PySide6.QtDBus.QDBusArgument

PySide6.QtDBus.QDBusArgument.__lshift__(arg)
Parameters

argPySide6.QtDBus.QDBusObjectPath

Return type

PySide6.QtDBus.QDBusArgument

PySide6.QtDBus.QDBusArgument.__lshift__(arg)
Parameters

argPySide6.QtCore.QByteArray

Return type

PySide6.QtDBus.QDBusArgument

PySide6.QtDBus.QDBusArgument.__lshift__(arg)
Parameters

arg – bool

Return type

PySide6.QtDBus.QDBusArgument

PySide6.QtDBus.QDBusArgument.__lshift__(pt)
Parameters

ptPySide6.QtCore.QPointF

Return type

PySide6.QtDBus.QDBusArgument

PySide6.QtDBus.QDBusArgument.__rshift__(arg)
Parameters

argushort

Return type

PySide6.QtDBus.QDBusArgument

PySide6.QtDBus.QDBusArgument.__rshift__(arg)
Parameters

arguint

Return type

PySide6.QtDBus.QDBusArgument

PySide6.QtDBus.QDBusArgument.__rshift__(arg)
Parameters

arg – str

Return type

PySide6.QtDBus.QDBusArgument

PySide6.QtDBus.QDBusArgument.__rshift__(arg)
Parameters

argshort

Return type

PySide6.QtDBus.QDBusArgument

PySide6.QtDBus.QDBusArgument.__rshift__(arg)
Parameters

argqulonglong

Return type

PySide6.QtDBus.QDBusArgument

PySide6.QtDBus.QDBusArgument.__rshift__(arg)
Parameters

argqlonglong

Return type

PySide6.QtDBus.QDBusArgument

PySide6.QtDBus.QDBusArgument.__rshift__(dt)
Parameters

dtPySide6.QtCore.QDateTime

Return type

PySide6.QtDBus.QDBusArgument

PySide6.QtDBus.QDBusArgument.__rshift__(arg)
Parameters

arg – int

Return type

PySide6.QtDBus.QDBusArgument

PySide6.QtDBus.QDBusArgument.__rshift__(arg)
Parameters

argdouble

Return type

PySide6.QtDBus.QDBusArgument

PySide6.QtDBus.QDBusArgument.__rshift__(arg)
Parameters

arg – bool

Return type

PySide6.QtDBus.QDBusArgument

PySide6.QtDBus.QDBusArgument.__rshift__(v)
Parameters

v – object

Return type

PySide6.QtDBus.QDBusArgument

PySide6.QtDBus.QDBusArgument.__rshift__(time)
Parameters

timePySide6.QtCore.QTime

Return type

PySide6.QtDBus.QDBusArgument

PySide6.QtDBus.QDBusArgument.__rshift__(arg)
Parameters

arg – list of strings

Return type

PySide6.QtDBus.QDBusArgument

PySide6.QtDBus.QDBusArgument.__rshift__(arg)
Parameters

arg – str

Return type

PySide6.QtDBus.QDBusArgument

PySide6.QtDBus.QDBusArgument.__rshift__(size)
Parameters

sizePySide6.QtCore.QSizeF

Return type

PySide6.QtDBus.QDBusArgument

PySide6.QtDBus.QDBusArgument.__rshift__(size)
Parameters

sizePySide6.QtCore.QSize

Return type

PySide6.QtDBus.QDBusArgument

PySide6.QtDBus.QDBusArgument.__rshift__(rect)
Parameters

rectPySide6.QtCore.QRectF

Return type

PySide6.QtDBus.QDBusArgument

PySide6.QtDBus.QDBusArgument.__rshift__(rect)
Parameters

rectPySide6.QtCore.QRect

Return type

PySide6.QtDBus.QDBusArgument

PySide6.QtDBus.QDBusArgument.__rshift__(pt)
Parameters

ptPySide6.QtCore.QPointF

Return type

PySide6.QtDBus.QDBusArgument

PySide6.QtDBus.QDBusArgument.__rshift__(pt)
Parameters

ptPySide6.QtCore.QPoint

Return type

PySide6.QtDBus.QDBusArgument

PySide6.QtDBus.QDBusArgument.__rshift__(line)
Parameters

linePySide6.QtCore.QLineF

Return type

PySide6.QtDBus.QDBusArgument

PySide6.QtDBus.QDBusArgument.__rshift__(line)
Parameters

linePySide6.QtCore.QLine

Return type

PySide6.QtDBus.QDBusArgument

PySide6.QtDBus.QDBusArgument.__rshift__(date)
Parameters

datePySide6.QtCore.QDate

Return type

PySide6.QtDBus.QDBusArgument

PySide6.QtDBus.QDBusArgument.__rshift__(arg)
Parameters

argPySide6.QtDBus.QDBusVariant

Return type

PySide6.QtDBus.QDBusArgument

PySide6.QtDBus.QDBusArgument.__rshift__(arg)
Parameters

argPySide6.QtDBus.QDBusUnixFileDescriptor

Return type

PySide6.QtDBus.QDBusArgument

PySide6.QtDBus.QDBusArgument.__rshift__(arg)
Parameters

argPySide6.QtDBus.QDBusSignature

Return type

PySide6.QtDBus.QDBusArgument

PySide6.QtDBus.QDBusArgument.__rshift__(arg)
Parameters

argPySide6.QtDBus.QDBusObjectPath

Return type

PySide6.QtDBus.QDBusArgument

PySide6.QtDBus.QDBusArgument.__rshift__(arg)
Parameters

argPySide6.QtCore.QByteArray

Return type

PySide6.QtDBus.QDBusArgument

PySide6.QtDBus.QDBusArgument.swap(other)
Parameters

otherPySide6.QtDBus.QDBusArgument

Swaps this QDBusArgument instance with other.