本页内容

qt_add_dbus_adaptor

为 D-Bus 接口生成一个适配器类。

该命令定义在Qt6 包的DBus 组件中。使用以下命令加载该包:

find_package(Qt6 REQUIRED COMPONENTS DBus)

该命令于 Qt 6.0 中引入。

语法

qt_add_dbus_adaptor(<VAR> dbus_spec header
    [parent_class]
    [basename]
    [classname]
)

如果禁用了无版本号的命令,请改用qt6_add_dbus_adaptor() 。它支持与本命令相同的参数集。

描述

生成一个 C++ 头文件,用于实现针对dbus_spec 中定义的 D-Bus 接口描述文件的适配器。生成的文件路径将被添加到<VAR> 中。生成的适配器类将parent_class 的指针作为QObject 父类。parent_class 应在header 中声明,该头文件将作为#include "header" 包含在生成的代码中。

该函数设置了对Qt D-Bus XML 编译器(qdbusxml2cpp)的调用,并以适配器模式运行。默认的文件名和类名由dbus_spec 基名的最后一个片段生成:

XML 文件头文件类名
org.example.chatchatadaptor.hChatAdaptor

您可以通过将basename 作为第五个参数传递,来更改要生成的头文件名称。系统会始终添加.h 后缀。

您可以通过将classname 作为第六个参数传递来更改默认类名。

示例

qt_add_dbus_adaptor(GENERATED_SOURCES org.example.chat.xml chat.h ChatMainWindow)

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