QDBusVariant Class

Die Klasse QDBusVariant ermöglicht es dem Programmierer, den vom D-Bus-Typensystem bereitgestellten Variantentyp zu identifizieren. Mehr...

Kopfzeile: #include <QDBusVariant>
CMake: find_package(Qt6 REQUIRED COMPONENTS DBus)
target_link_libraries(mytarget PRIVATE Qt6::DBus)
qmake: QT += dbus

Öffentliche Funktionen

QDBusVariant()
QDBusVariant(const QVariant &variant)
void setVariant(const QVariant &variant)
void swap(QDBusVariant &other)
QVariant variant() const

Detaillierte Beschreibung

Eine D-Bus-Funktion, die eine ganze Zahl, eine D-Bus-Variante und eine Zeichenkette als Parameter benötigt, kann mit der folgenden Argumentliste aufgerufen werden (siehe QDBusMessage::setArguments()):

    QList<QVariant> arguments;
    arguments << QVariant(42) << QVariant::fromValue(QDBusVariant(43)) << QVariant("hello");
    myDBusMessage.setArguments(arguments);

Wenn eine D-Bus-Funktion eine D-Bus-Variante zurückgibt, kann diese wie folgt abgerufen werden:

    // call a D-Bus function that returns a D-Bus variant
    QVariant v = callMyDBusFunction();
    // retrieve the D-Bus variant
    QDBusVariant dbusVariant = qvariant_cast<QDBusVariant>(v);
    // retrieve the actual value stored in the D-Bus variant
    QVariant result = dbusVariant.variant();

Die QVariant innerhalb einer QDBusVariant ist erforderlich, um zwischen einem normalen D-Bus Wert und einem Wert innerhalb einer D-Bus Variante zu unterscheiden.

Siehe auch Das Qt D-Bus Typsystem.

Dokumentation der Mitgliedsfunktionen

[noexcept] QDBusVariant::QDBusVariant()

Konstruiert eine neue D-Bus-Variante.

[explicit] QDBusVariant::QDBusVariant(const QVariant &variant)

Konstruiert eine neue Qt D-Bus Variante aus der gegebenen Qt variant.

Siehe auch setVariant().

void QDBusVariant::setVariant(const QVariant &variant)

Weist dieser D-Bus Variante den Wert der angegebenen Qt variant zu.

Siehe auch variant().

[noexcept] void QDBusVariant::swap(QDBusVariant &other)

Tauscht diese Variante mit other aus. Dieser Vorgang ist sehr schnell und schlägt nie fehl.

QVariant QDBusVariant::variant() const

Gibt diese D-Bus-Variante als QVariant Objekt zurück.

Siehe auch setVariant().

© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.