qt_generate_moc

在输入文件上调用 moc。

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

find_package(Qt6 REQUIRED COMPONENTS Core)

此命令在 Qt 5.0 中引入。

简介

qt_generate_moc(src_file dest_file
                [TARGET target])

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

说明

创建一条规则,在src_file 上调用Meta-Object Compiler (moc),并将输出存储在dest_file 中。

注意: 这是一个低级宏。请参阅CMake AUTOMOC 文档,了解使用moc 处理源文件的更便捷方法。qt_wrap_cpp也类似,但会自动为您生成临时文件路径。

参数

你可以设置一个明确的TARGET 。这将确保在使用moc 扫描源文件时,目标属性INCLUDE_DIRECTORIESCOMPILE_DEFINITIONS 也会被使用。

示例

qt_generate_moc(main.cpp main.moc TARGET myapp)

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