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 に保存するルールを作成します。
注:これは 低レベルのマクロです。ソースファイルをmoc で処理するためのより便利な方法については、CMake AUTOMOC ドキュメントを参照してください。qt_wrap_cpp()も同様ですが、一時ファイルのパスを自動的に生成してくれます。
引数
TARGET を明示的に設定することができます。これにより、moc を使用してソースファイルをスキャンする際、ターゲットプロパティINCLUDE_DIRECTORIES およびCOMPILE_DEFINITIONS も確実に使用されるようになります。
例
qt_generate_moc(main.cpp main.moc TARGET myapp)© 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.