本页内容

qt_add_dbus_interface

根据 D-Bus 接口描述文件生成实现该接口的 C++ 源代码。

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

find_package(Qt6 REQUIRED COMPONENTS DBus)

该命令于 Qt 6.0 中引入。

语法

qt_add_dbus_interface(<VAR> dbus_spec basename)

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

描述

为在dbus_spec 中定义的 D-Bus 接口描述文件生成实现该接口的 C++ 源代码。生成的文件名称基于basename :basename.h 、basename.cpp 、basename.moc 。这些文件的路径将被添加到<VAR> 中。

该函数以接口(代理)模式调用Qt D-Bus XML编译器(qdbusxml2cpp)。默认情况下,qdbusxml2cpp 会生成一个以接口名称命名的C++类,并带有命名空间别名:

D-Bus 接口名称类名命名空间名称
org.example.chatOrgExampleChatInterfaceorg.example.chat

选项

可通过在dbus_spec 上使用set_source_files_properties 来设置选项:

选项值说明
CLASSNAMEclass_name使用class_name 覆盖默认接口类名称。
NO_NAMESPACE布尔型如果设置为ON ,则不生成带命名空间的名称。
INCLUDEpath在生成的代码中添加#include "path" 。

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