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)

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