QDBusAbstractAdaptor Class

QDBusAbstractAdaptor 类是 D-Bus 适配器类的基类。更多

Header: #include <QDBusAbstractAdaptor>
CMake: find_package(Qt6 REQUIRED COMPONENTS DBus)
target_link_libraries(mytarget PRIVATE Qt6::DBus)
qmake: QT += dbus
继承: QObject

公共函数

保护函数

QDBusAbstractAdaptor(QObject *obj)
bool autoRelaySignals() const
void setAutoRelaySignals(bool enable)

详细说明

QDBusAbstractAdaptor 类是所有打算使用 D-Bus 向外部世界提供接口的对象的起点。具体做法是将一个或多个从 QDBusAbstractAdaptor 派生的类附加到一个普通的QObject ,然后将该QObject 注册到QDBusConnection::registerObject 。QDBusAbstractAdaptor 对象旨在成为轻量级的封装器,主要是将调用转发到真正的对象(其父对象)以及来自它的信号。

每个 QDBusAbstractAdaptor 派生类都应在类定义中使用Q_CLASSINFO 宏定义它要实现的 D-Bus 接口。请注意,这种方式只能公开一个接口。

QDBusAbstractAdaptor 使用信号、槽和属性的标准QObject 机制来确定向总线输出哪些信号、方法和属性。QDBusAbstractAdaptor 派生类发出的任何信号都将通过该对象注册的任何 D-Bus 连接自动转发。

从 QDBusAbstractAdaptor 派生的类必须使用new 操作符在堆上创建,且用户不得删除这些类(当与之连接的对象被删除时,这些类将自动删除)。

另请参阅 使用适配器QDBusConnection

成员函数文档

[explicit protected] QDBusAbstractAdaptor::QDBusAbstractAdaptor(QObject *obj)

构建 QDBusAbstractAdaptor,父对象为obj

[virtual noexcept] QDBusAbstractAdaptor::~QDBusAbstractAdaptor()

销毁适配器。

警告 当适配器指向的真实对象被销毁时,适配器也会自动销毁。请勿自行删除适配器。

[protected] bool QDBusAbstractAdaptor::autoRelaySignals() const

如果启用了来自真实对象的自动信号中继(参见 object() ),则返回true ,否则返回false

另请参见 setAutoRelaySignals().

[protected] void QDBusAbstractAdaptor::setAutoRelaySignals(bool enable)

切换真实对象的自动信号中继(参见 object())。

自动信号中继包括两个类中方法签名完全相同的父对象上信号之间的连接。

如果enable 设置为 true,则连接信号;如果设置为 false,则断开所有信号。

另请参见 autoRelaySignals().

宏文档

Q_NOREPLY

Q_NOREPLY 宏可用于标记要调用的方法,并且在从QDBusInterface::call() 返回之前不等待该方法完成处理。被调用的方法不能返回任何输出参数,如果返回,任何此类参数都将被丢弃。

您可以在自己的适配器中使用这个宏,方法的返回值(必须是 "void")必须在类声明中的 "void "之前,如示例所示:

Q_NOREPLY void myMethod();

该宏在方法实现中(类声明之外)的存在是可选的。

另请参阅 Qt D-Bus 适配程序的使用

© 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.