在本页中

qt_generate_wayland_protocol_client_sources

为 Wayland 协议 .XML 文件生成客户端 C++ 绑定

该命令定义在Qt6 软件包的WaylandClient 组件中,可以像这样加载:

find_package(Qt6 REQUIRED COMPONENTS WaylandClient)

该命令在 Qt 6.0 中引入。

简介

qt_generate_wayland_protocol_client_sources(target
                                            [PUBLIC_CODE | PRIVATE_CODE]
                                            [NO_INCLUDE_CORE_ONLY]
                                            FILES file1.xml [file2.xml ...])

如果禁用了无版本命令,请使用qt6_generate_wayland_protocol_client_sources() 代替。它支持与此命令相同的参数集。

说明

qt_generate_wayland_protocol_client_sources() 创建构建步骤,以便在一个或多个 Wayland 协议文件上运行wayland-scannerqtwaylandscanner 。这些工具将反过来生成实现协议的 C 和 C++ 绑定代码,生成的文件将作为target 的一部分进行构建。

PUBLIC_CODEPRIVATE_CODE 选项(在 Qt 6.8 中添加)与wayland-scannerpublic-codeprivate-code 选项相对应。PUBLIC_CODE 将使wayland-scanner 生成的代码中的符号被导出。为实现向后兼容,默认情况下使用PUBLIC_CODE ,但一般情况下强烈建议使用PRIVATE_CODE

默认情况下,wayland-scanner--include-core-only 参数一起调用,以确保生成的代码包含"wayland-client-core.h" 。可以使用NO_INCLUDE_CORE_ONLY 选项禁用这一行为,它将包含切换为"wayland-client.h"

注意: 一般不建议使用NO_INCLUDE_CORE_ONLY"wayland-client.h" 包含预编译版本的核心 Wayland 协议,可能会与更新的协议版本或其他头文件(如旧版本的 Vulkan)冲突。只有当你对核心头文件中没有的类型有特殊要求,并意识到潜在的编译冲突时,才会使用该选项。

qt_generate_wayland_protocol_client_sources() 会触发生成实现协议客户端所需的文件。

请参阅自定义 Shell自定义扩展示例,了解如何使用这些函数。

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