PySide6.QtDBus.QDBusArgument¶
- class QDBusArgument¶
The
QDBusArgument
class is used to marshall and demarshall D-Bus arguments. More…Synopsis¶
Methods¶
def
__init__()
def
appendVariant()
def
asVariant()
def
atEnd()
def
beginArray()
def
beginMap()
def
beginMapEntry()
def
beginStructure()
def
currentType()
def
endArray()
def
endMap()
def
endMapEntry()
def
endStructure()
def
__lshift__()
def
__rshift__()
def
swap()
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 withQDBusArgument
. 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<<
andoperator>>
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 theoperator>>
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 Adaptorsqdbus_cast()
- 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
- __init__()¶
Constructs an empty
QDBusArgument
argument.An empty
QDBusArgument
object does not allow either reading or writing to be performed.- __init__(other)
- Parameters:
other –
QDBusArgument
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.
- 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()¶
- Return type:
bool
Returns
true
if there are no more elements to be extracted from thisQDBusArgument
. This function is usually used inQDBusArgument
objects returned frombeginMap()
andbeginArray()
.- 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 asstd::list
,std::vector
, etc.See also
- beginArray(elementMetaType)
- Parameters:
elementMetaType –
QMetaType
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 asstd::list
,std::vector
, etc.See also
- 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 asstd::list
,std::vector
, etc.See also
- 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.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
andvalueMetaType
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<<
oroperator>>
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
andvalueMetaType
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<<
oroperator>>
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.See also
- 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
See also
- currentSignature()¶
- Return type:
str
- currentType()¶
- Return type:
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
- endMap()¶
Closes the D-Bus map and allow extracting of the next element after the map.
See also
- endMapEntry()¶
Closes the D-Bus map entry and allow extracting of the next element on the map.
See also
- endStructure()¶
Closes the D-Bus structure and allow extracting of the next element after the structure.
See also
- __lshift__(arg)¶
- Parameters:
arg – bool
- Return type:
This is an overloaded function.
Appends the primitive value
arg
of typeBOOLEAN
to the D-Bus stream.- __lshift__(arg)
- Parameters:
arg –
QByteArray
- Return type:
This is an overloaded function.
Appends the QByteArray given by
arg
asARRAY 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:
arg –
QDBusObjectPath
- Return type:
- __lshift__(arg)
- Parameters:
arg –
QDBusSignature
- Return type:
- __lshift__(arg)
- Parameters:
arg –
QDBusUnixFileDescriptor
- Return type:
- __lshift__(arg)
- Parameters:
arg –
QDBusVariant
- Return type:
This is an overloaded function.
Appends the primitive value
arg
of typeVARIANT
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__(date)
- Parameters:
date –
QDate
- Return type:
- __lshift__(dt)
- Parameters:
dt –
QDateTime
- Return type:
- __lshift__(map)
- Parameters:
map – Dictionary with keys of type .QString and values of type QVariant.
- Return type:
- __lshift__(line)
- Parameters:
line –
QLine
- Return type:
- __lshift__(line)
- Parameters:
line –
QLineF
- Return type:
- __lshift__(list)
- Parameters:
list – .list of QVariant
- Return type:
- __lshift__(map)
- Parameters:
map – Dictionary with keys of type .QString and values of type QVariant.
- Return type:
- __lshift__(pt)
- Parameters:
pt –
QPoint
- Return type:
- __lshift__(pt)
- Parameters:
pt –
QPointF
- Return type:
- __lshift__(rect)
- Parameters:
rect –
QRect
- Return type:
- __lshift__(rect)
- Parameters:
rect –
QRectF
- Return type:
- __lshift__(size)
- Parameters:
size –
QSize
- Return type:
- __lshift__(size)
- Parameters:
size –
QSizeF
- Return type:
- __lshift__(arg)
- Parameters:
arg – str
- Return type:
This is an overloaded function.
Appends the primitive value
arg
of typeSTRING
(Unicode character string) to the D-Bus stream.- __lshift__(arg)
- Parameters:
arg – list of strings
- Return type:
This is an overloaded function.
Appends the QStringList given by
arg
asARRAY 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__(time)
- Parameters:
time –
QTime
- Return type:
- __lshift__(arg)
- Parameters:
arg – float
- Return type:
This is an overloaded function.
Appends the primitive value
arg
of typeDOUBLE
(double-precision floating-point) to the D-Bus stream.- __lshift__(arg)
- Parameters:
arg – int
- Return type:
This is an overloaded function.
Appends the primitive value
arg
of typeINT32
to the D-Bus stream.- __lshift__(arg)
- Parameters:
arg – int
- Return type:
This is an overloaded function.
Appends the primitive value
arg
of typeINT64
to the D-Bus stream.- __lshift__(arg)
- Parameters:
arg – int
- Return type:
This is an overloaded function.
Appends the primitive value
arg
of typeUINT64
to the D-Bus stream.- __lshift__(arg)
- Parameters:
arg – int
- Return type:
This is an overloaded function.
Appends the primitive value
arg
of typeINT16
to the D-Bus stream.- __lshift__(arg)
- Parameters:
arg – int
- Return type:
Appends the primitive value
arg
of typeBYTE
to the D-Bus stream.- __lshift__(arg)
- Parameters:
arg – int
- Return type:
This is an overloaded function.
Appends the primitive value
arg
of typeUINT32
to the D-Bus stream.- __lshift__(arg)
- Parameters:
arg – int
- Return type:
This is an overloaded function.
Appends the primitive value
arg
of typeUINT16
to the D-Bus stream.- __rshift__(arg)¶
- Parameters:
arg –
QByteArray
- Return type:
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.
- __rshift__(arg)
- Parameters:
arg –
QDBusObjectPath
- Return type:
- __rshift__(arg)
- Parameters:
arg –
QDBusSignature
- Return type:
- __rshift__(arg)
- Parameters:
arg –
QDBusUnixFileDescriptor
- Return type:
- __rshift__(arg)
- Parameters:
arg –
QDBusVariant
- Return type:
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 returnedQDBusVariant
will contain anotherQDBusArgument
. It is your responsibility to further demarshall it into another type.- __rshift__(date)
- Parameters:
date –
QDate
- Return type:
- __rshift__(dt)
- Parameters:
dt –
QDateTime
- Return type:
- __rshift__(line)
- Parameters:
line –
QLine
- Return type:
- __rshift__(line)
- Parameters:
line –
QLineF
- Return type:
- __rshift__(pt)
- Parameters:
pt –
QPoint
- Return type:
- __rshift__(pt)
- Parameters:
pt –
QPointF
- Return type:
- __rshift__(rect)
- Parameters:
rect –
QRect
- Return type:
- __rshift__(rect)
- Parameters:
rect –
QRectF
- Return type:
- __rshift__(size)
- Parameters:
size –
QSize
- Return type:
- __rshift__(size)
- Parameters:
size –
QSizeF
- Return type:
- __rshift__(arg)
- Parameters:
arg – str
- Return type:
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:
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:
time –
QTime
- Return type:
- __rshift__(v)
- Parameters:
v – object
- Return type:
- __rshift__(arg)
- Parameters:
arg – bool
- Return type:
This is an overloaded function.
Extracts one D-Bus primitive argument of type
BOOLEAN
from the D-Bus stream.- __rshift__(arg)
- Parameters:
arg –
double
- Return type:
This is an overloaded function.
Extracts one D-Bus primitive argument of type
DOUBLE
(double-precision floating point) from the D-Bus stream.- __rshift__(arg)
- Parameters:
arg – int
- Return type:
This is an overloaded function.
Extracts one D-Bus primitive argument of type
INT32
from the D-Bus stream.- __rshift__(arg)
- Parameters:
arg –
qlonglong
- Return type:
This is an overloaded function.
Extracts one D-Bus primitive argument of type
INT64
from the D-Bus stream.- __rshift__(arg)
- Parameters:
arg –
qulonglong
- Return type:
This is an overloaded function.
Extracts one D-Bus primitive argument of type
UINT64
from the D-Bus stream.- __rshift__(arg)
- Parameters:
arg –
short
- Return type:
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:
Extracts one D-Bus primitive argument of type
BYTE
from the D-Bus stream and puts it intoarg
.- __rshift__(arg)
- Parameters:
arg –
uint
- Return type:
This is an overloaded function.
Extracts one D-Bus primitive argument of type
UINT32
from the D-Bus stream.- __rshift__(arg)
- Parameters:
arg –
ushort
- Return type:
This is an overloaded function.
Extracts one D-Bus primitive argument of type
UINT16
from the D-Bus stream.- swap(other)¶
- Parameters:
other –
QDBusArgument
Swaps this
QDBusArgument
instance withother
.