QDBusVariant Class
QDBusVariant 类使程序员能够识别 D-Bus 类型系统提供的变体类型。更多内容...
| 头文件: | #include <QDBusVariant> |
| CMake: | find_package(Qt6 REQUIRED COMPONENTS DBus) target_link_libraries(mytarget PRIVATE Qt6::DBus) |
| qmake: | QT += dbus |
公共函数
| QDBusVariant() | |
| QDBusVariant(const QVariant &variant) | |
| void | setVariant(const QVariant &variant) |
| void | swap(QDBusVariant &other) |
| QVariant | variant() const |
详细说明
一个接受整数、D-Bus 变体和字符串作为参数的 D-Bus 函数,可以使用以下参数列表进行调用(参见QDBusMessage::setArguments()):
QList<QVariant> arguments;
arguments << QVariant(42) << QVariant::fromValue(QDBusVariant(43)) << QVariant("hello");
myDBusMessage.setArguments(arguments);当 D-Bus 函数返回一个 D-Bus 变体时,可通过以下方式获取:
// 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();QDBusVariant 中的QVariant 用于区分普通 D-Bus 值与 D-Bus 变体内的值。
另请参阅 《Qt D-Bus 类型系统》。
成员函数文档
[noexcept] QDBusVariant::QDBusVariant()
创建一个新的 D-Bus 变体。
[explicit] QDBusVariant::QDBusVariant(const QVariant &variant)
根据给定的 Qt XMLvariant 构建一个新的 Qt D-Bus 变体。
另请参阅 setVariant()。
void QDBusVariant::setVariant(const QVariant &variant)
将给定的 Qt XMLvariant 的值分配给此 Qt D-Bus 变体。
另请参阅 variant()。
[noexcept] void QDBusVariant::swap(QDBusVariant &other)
将此变体与other 互换。此操作非常快,且绝不会失败。
QVariant QDBusVariant::variant() const
将此 D-Bus 变体作为QVariant 对象返回。
另请参阅 setVariant()。
© 2026 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.