QDBusArgument Class
The QDBusArgument class is used to marshall and demarshall D-Bus arguments. More…
| Header | #include <QDBusArgument> |
|---|---|
| CMake | target_link_libraries(app PRIVATE Nt::DBus) |
| Module | Nt D-Bus C++ Classes |
List of all members, including inherited members
Public Types
| enum | ElementType |
Public Functions
| QDBusArgument() | |
| QDBusArgument(const QDBusArgument &other) | |
| QDBusArgument(QDBusArgument &&other) | |
| QDBusArgument & | operator=(const QDBusArgument &other) |
| QDBusArgument & | operator=(QDBusArgument &&other) |
| ~QDBusArgument() | |
| void | swap(QDBusArgument &other) |
| QDBusArgument & | operator<<(uchar arg) |
| QDBusArgument & | operator<<(bool arg) |
| QDBusArgument & | operator<<(short arg) |
| QDBusArgument & | operator<<(ushort arg) |
| QDBusArgument & | operator<<(int arg) |
| QDBusArgument & | operator<<(uint arg) |
| QDBusArgument & | operator<<(qlonglong arg) |
| QDBusArgument & | operator<<(qulonglong arg) |
| QDBusArgument & | operator<<(long arg) |
| QDBusArgument & | operator<<(unsigned long arg) |
| QDBusArgument & | operator<<(double arg) |
| QDBusArgument & | operator<<(const QString &arg) |
| QDBusArgument & | operator<<(const QDBusVariant &arg) |
| QDBusArgument & | operator<<(const QDBusObjectPath &arg) |
| QDBusArgument & | operator<<(const QDBusSignature &arg) |
| QDBusArgument & | operator<<(const QDBusUnixFileDescriptor &arg) |
| QDBusArgument & | operator<<(const QStringList &arg) |
| QDBusArgument & | operator<<(const QByteArray &arg) |
| void | beginStructure() |
| void | endStructure() |
| void | beginArray(QMetaType elementMetaType) |
| void | beginArray(int elementMetaTypeId) |
| void | endArray() |
| void | beginMap(QMetaType keyMetaType, QMetaType valueMetaType) |
| void | beginMap(int keyMetaTypeId, int valueMetaTypeId) |
| void | endMap() |
| void | beginMapEntry() |
| void | endMapEntry() |
| void | appendVariant(const QVariant &value) |
| QString | currentSignature() const |
| ElementType | currentType() const |
| const QDBusArgument & | operator>>(uchar &arg) const |
| const QDBusArgument & | operator>>(bool &arg) const |
| const QDBusArgument & | operator>>(short &arg) const |
| const QDBusArgument & | operator>>(ushort &arg) const |
| const QDBusArgument & | operator>>(int &arg) const |
| const QDBusArgument & | operator>>(uint &arg) const |
| const QDBusArgument & | operator>>(qlonglong &arg) const |
| const QDBusArgument & | operator>>(qulonglong &arg) const |
| const QDBusArgument & | operator>>(long &arg) const |
| const QDBusArgument & | operator>>(unsigned long &arg) const |
| const QDBusArgument & | operator>>(double &arg) const |
| const QDBusArgument & | operator>>(QString &arg) const |
| const QDBusArgument & | operator>>(QDBusVariant &arg) const |
| const QDBusArgument & | operator>>(QDBusObjectPath &arg) const |
| const QDBusArgument & | operator>>(QDBusSignature &arg) const |
| const QDBusArgument & | operator>>(QDBusUnixFileDescriptor &arg) const |
| const QDBusArgument & | operator>>(QStringList &arg) const |
| const QDBusArgument & | operator>>(QByteArray &arg) const |
| void | beginStructure() const |
| void | endStructure() const |
| void | beginArray() const |
| void | endArray() const |
| void | beginMap() const |
| void | endMap() const |
| void | beginMapEntry() const |
| void | endMapEntry() const |
| bool | atEnd() const |
| QVariant | asVariant() const |
Detailed Description
To send a type of your own, give it stream operators and register it with qDBusRegisterMetaType(). A structure maps to a D-Bus structure with beginStructure() and endStructure():
struct Fix { double lat; double lon; };
Q_DECLARE_METATYPE(Fix)
QDBusArgument &operator<<(QDBusArgument &arg, const Fix &fix) {
arg.beginStructure();
arg << fix.lat << fix.lon;
arg.endStructure();
return arg;
}
const QDBusArgument &operator>>(const QDBusArgument &arg, Fix &fix) {
arg.beginStructure();
arg >> fix.lat >> fix.lon;
arg.endStructure();
return arg;
}
qDBusRegisterMetaType<Fix>();
Containers, structures and dictionaries of a received message that Nt has no C++ type for arrive in a QVariant as a QDBusArgument. qdbus_cast() turns one into a type that is registered:
QVariantMap map = qdbus_cast<QVariantMap>(reply.arguments().first());
A QDBusArgument that was default-constructed is for writing; one that came from a message is for reading. Reading from a copy does not move the position of the original.
See also QDBusMetaType, QDBusVariant and QDBusMessage.
Differences from Qt
The stream operators for QDate, QTime, QDateTime and the geometry types are missing. A std::pair takes the place of QPair, and std::tuple maps to a structure as well. Marshalling long and unsigned long is supported because Nt's qint64 is long on Linux. A value of the wrong type is not read: the function prints a warning, returns a default value and skips the value on the wire.
Member Type Documentation
enum QDBusArgument::ElementType
Describes the next value of an argument that is being read.
| Constant | Description |
|---|---|
QDBusArgument::BasicType | A basic type: a number, a string, an object path or a signature. |
QDBusArgument::VariantType | A D-Bus variant. |
QDBusArgument::ArrayType | An array, read with beginArray(). |
QDBusArgument::StructureType | A structure, read with beginStructure(). |
QDBusArgument::MapType | A dictionary, read with beginMap(). |
QDBusArgument::MapEntryType | An entry of a dictionary, read with beginMapEntry(). |
QDBusArgument::UnknownType | There is no value at this position. |
Member Function Documentation
QDBusArgument::QDBusArgument()
Constructs an empty argument for writing.
QDBusArgument::QDBusArgument(const QDBusArgument &other)
Constructs a copy of other. Reading from one of them does not move the position of the other; writing to one writes to both.
QDBusArgument::QDBusArgument(QDBusArgument &&other)
Constructs an argument that takes the place of other.
QDBusArgument::~QDBusArgument()
Destroys the argument.
void QDBusArgument::appendVariant(const QVariant &value)
Appends value, which can have any type that is known to the D-Bus type system. It is not wrapped in a D-Bus variant.
QVariant QDBusArgument::asVariant() const
Reads the value at the current position and returns it in a QVariant: basic types, string lists and byte arrays as themselves, a variant as a QDBusVariant, and other containers as a QDBusArgument.
bool QDBusArgument::atEnd() const
Returns true if there are no more values in the current container, or in the argument.
void QDBusArgument::beginArray(QMetaType elementMetaType)
Opens an array with elements of the type elementMetaType, which must be known to the D-Bus type system. The values that follow are its elements, up to endArray().
void QDBusArgument::beginArray(int elementMetaTypeId)
This is an overloaded function.
Opens an array whose elements have the meta-type id elementMetaTypeId.
void QDBusArgument::beginArray() const
This is an overloaded function.
Enters the array at the current position. Read elements while atEnd() is false.
void QDBusArgument::beginMap(QMetaType keyMetaType, QMetaType valueMetaType)
Opens a dictionary with keys of the type keyMetaType, which must be a basic type, and values of the type valueMetaType. Enclose each pair in beginMapEntry() and endMapEntry().
void QDBusArgument::beginMap(int keyMetaTypeId, int valueMetaTypeId)
This is an overloaded function.
Opens a map whose keys and values have the meta-type ids keyMetaTypeId and valueMetaTypeId.
void QDBusArgument::beginMap() const
This is an overloaded function.
Enters the dictionary at the current position. Read entries while atEnd() is false.
void QDBusArgument::beginMapEntry()
Opens an entry of a dictionary. The two values that follow are its key and its value.
void QDBusArgument::beginMapEntry() const
This is an overloaded function.
Enters the dictionary entry at the current position.
void QDBusArgument::beginStructure()
Opens a structure. The values that follow are its members, up to endStructure().
void QDBusArgument::beginStructure() const
This is an overloaded function.
Enters the structure at the current position.
QString QDBusArgument::currentSignature() const
Returns the signature of the value at the current position of an argument that is being read, or of everything written so far to one that is being written.
ElementType QDBusArgument::currentType() const
Returns the kind of the value at the current position, or UnknownType if there is none or the argument is being written.
void QDBusArgument::endArray()
Closes the array that beginArray() opened.
void QDBusArgument::endArray() const
This is an overloaded function.
Leaves the current array, skipping elements that were not read.
void QDBusArgument::endMap()
Closes the dictionary that beginMap() opened.
void QDBusArgument::endMap() const
This is an overloaded function.
Leaves the current dictionary, skipping entries that were not read.
void QDBusArgument::endMapEntry()
Closes the entry that beginMapEntry() opened.
void QDBusArgument::endMapEntry() const
This is an overloaded function.
Leaves the current dictionary entry.
void QDBusArgument::endStructure()
Closes the structure that beginStructure() opened.
void QDBusArgument::endStructure() const
This is an overloaded function.
Leaves the current structure, skipping members that were not read.
QDBusArgument & QDBusArgument::operator<<(uchar arg)
Appends the byte arg and returns a reference to this argument.
QDBusArgument & QDBusArgument::operator<<(bool arg)
This is an overloaded function.
Appends the boolean arg.
QDBusArgument & QDBusArgument::operator<<(short arg)
This is an overloaded function.
Appends the 16 bit integer arg.
QDBusArgument & QDBusArgument::operator<<(ushort arg)
This is an overloaded function.
Appends the unsigned 16 bit integer arg.
QDBusArgument & QDBusArgument::operator<<(int arg)
This is an overloaded function.
Appends the 32 bit integer arg.
QDBusArgument & QDBusArgument::operator<<(uint arg)
This is an overloaded function.
Appends the unsigned 32 bit integer arg.
QDBusArgument & QDBusArgument::operator<<(qlonglong arg)
This is an overloaded function.
Appends the 64 bit integer arg.
QDBusArgument & QDBusArgument::operator<<(qulonglong arg)
This is an overloaded function.
Appends the unsigned 64 bit integer arg.
QDBusArgument & QDBusArgument::operator<<(long arg)
This is an overloaded function.
Appends arg as a 64 bit integer.
QDBusArgument & QDBusArgument::operator<<(unsigned long arg)
This is an overloaded function.
Appends arg as an unsigned 64 bit integer.
QDBusArgument & QDBusArgument::operator<<(double arg)
This is an overloaded function.
Appends the floating-point number arg.
QDBusArgument & QDBusArgument::operator<<(const QString &arg)
This is an overloaded function.
Appends the string arg.
QDBusArgument & QDBusArgument::operator<<(const QDBusVariant &arg)
This is an overloaded function.
Appends the variant arg.
QDBusArgument & QDBusArgument::operator<<(const QDBusObjectPath &arg)
This is an overloaded function.
Appends the object path arg.
QDBusArgument & QDBusArgument::operator<<(const QDBusSignature &arg)
This is an overloaded function.
Appends the signature arg.
QDBusArgument & QDBusArgument::operator<<(const QDBusUnixFileDescriptor &arg)
This is an overloaded function.
Appends the file descriptor arg.
QDBusArgument & QDBusArgument::operator<<(const QStringList &arg)
This is an overloaded function.
Appends arg as an array of strings.
QDBusArgument & QDBusArgument::operator<<(const QByteArray &arg)
This is an overloaded function.
Appends arg as an array of bytes.
QDBusArgument & QDBusArgument::operator=(const QDBusArgument &other)
Makes this argument a copy of other and returns a reference to it.
QDBusArgument & QDBusArgument::operator=(QDBusArgument &&other)
Moves other into this argument and returns a reference to it.
const QDBusArgument & QDBusArgument::operator>>(uchar &arg) const
Reads a byte into arg and returns a reference to this argument.
const QDBusArgument & QDBusArgument::operator>>(bool &arg) const
This is an overloaded function.
Reads a boolean into arg.
const QDBusArgument & QDBusArgument::operator>>(short &arg) const
This is an overloaded function.
Reads a 16 bit integer into arg.
const QDBusArgument & QDBusArgument::operator>>(ushort &arg) const
This is an overloaded function.
Reads an unsigned 16 bit integer into arg.
const QDBusArgument & QDBusArgument::operator>>(int &arg) const
This is an overloaded function.
Reads a 32 bit integer into arg.
const QDBusArgument & QDBusArgument::operator>>(uint &arg) const
This is an overloaded function.
Reads an unsigned 32 bit integer into arg.
const QDBusArgument & QDBusArgument::operator>>(qlonglong &arg) const
This is an overloaded function.
Reads a 64 bit integer into arg.
const QDBusArgument & QDBusArgument::operator>>(qulonglong &arg) const
This is an overloaded function.
Reads an unsigned 64 bit integer into arg.
const QDBusArgument & QDBusArgument::operator>>(long &arg) const
This is an overloaded function.
Reads a 64 bit integer into arg.
const QDBusArgument & QDBusArgument::operator>>(unsigned long &arg) const
This is an overloaded function.
Reads an unsigned 64 bit integer into arg.
const QDBusArgument & QDBusArgument::operator>>(double &arg) const
This is an overloaded function.
Reads a floating-point number into arg.
const QDBusArgument & QDBusArgument::operator>>(QString &arg) const
This is an overloaded function.
Reads a string into arg.
const QDBusArgument & QDBusArgument::operator>>(QDBusVariant &arg) const
This is an overloaded function.
Reads a variant into arg.
const QDBusArgument & QDBusArgument::operator>>(QDBusObjectPath &arg) const
This is an overloaded function.
Reads an object path into arg.
const QDBusArgument & QDBusArgument::operator>>(QDBusSignature &arg) const
This is an overloaded function.
Reads a signature into arg.
const QDBusArgument & QDBusArgument::operator>>(QDBusUnixFileDescriptor &arg) const
This is an overloaded function.
Reads a file descriptor into arg.
const QDBusArgument & QDBusArgument::operator>>(QStringList &arg) const
This is an overloaded function.
Reads an array of strings into arg.
const QDBusArgument & QDBusArgument::operator>>(QByteArray &arg) const
This is an overloaded function.
Reads an array of bytes into arg.
void QDBusArgument::swap(QDBusArgument &other)
Swaps this argument with other.