Qt6新建项目构建失败求助:默认生成文件未修改仍报错
Qt6 CMake自动生成项目构建失败
环境与问题
使用Windows 11、Qt Creator 19.0.0、Qt6.11.0创建默认Qt Quick项目,未修改任何自动生成文件,构建时在自动QML类型注册阶段报错,终止码为2。
错误输出
jom: parallel job execution disabled for Makefile [ 45%] Running moc --collect-json for target appuntitled [ 50%] Generating meta_types/qt6appuntitled_metatypes.json [ 54%] Automatic QML type registration for target appuntitled jom: F:\shared\projects\tests\untitled\build\Desktop_Qt_6_11_0_MSVC2022_64bit-Debug\CMakeFiles\appuntitled.dir\build.make [appuntitled_qmltyperegistrations.cpp] Error 1 jom: F:\shared\projects\tests\untitled\build\Desktop_Qt_6_11_0_MSVC2022_64bit-Debug\CMakeFiles\Makefile2 [CMakeFiles\appuntitled.dir\all] Error 2 jom: F:\shared\projects\tests\untitled\build\Desktop_Qt_6_11_0_MSVC2022_64bit-Debug\CMakeFiles\Makefile2 [CMakeFiles\appuntitled.dir\rule] Error 2 jom: F:\shared\projects\tests\untitled\build\Desktop_Qt_6_11_0_MSVC2022_64bit-Debug\Makefile [appuntitled] Error 2 16:10:52: The command "D:\Qt\Tools\CMake_64\bin\cmake.exe --build F:/shared/projects/tests/untitled/build/Desktop_Qt_6_11_0_MSVC2022_64bit-Debug --target appuntitled" terminated with exit code 2. 16:10:52: Error while building/deploying project untitled (kit: Desktop Qt 6.11.0 MSVC2022 64bit) 16:10:52: When executing step "构建" 16:10:52: Elapsed time: 00:03.
自动生成的CMakeLists.txt
cmake_minimum_required(VERSION 3.16) project(untitled VERSION 0.1 LANGUAGES CXX) set(CMAKE_CXX_STANDARD_REQUIRED ON) find_package(Qt6 REQUIRED COMPONENTS Quick) qt_standard_project_setup(REQUIRES 6.10) qt_add_executable(appuntitled main.cpp ) qt_add_qml_module(appuntitled URI untitled QML_FILES Main.qml ) # Qt for iOS sets MACOSX_BUNDLE_GUI_IDENTIFIER automatically since Qt 6.1. # If you are developing for iOS or macOS you should consider setting an # explicit, fixed bundle identifier manually though. set_target_properties(appuntitled PROPERTIES # MACOSX_BUNDLE_GUI_IDENTIFIER com.example.appuntitled MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION} MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR} MACOSX_BUNDLE TRUE WIN32_EXECUTABLE TRUE ) target_link_libraries(appuntitled PRIVATE Qt6::Quick ) install(TARGETS appuntitled BUNDLE DESTINATION . LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} )
解决方法
- 检查项目路径,避免包含非ASCII字符或空格,改用纯英文短路径
- 禁用并行构建:在Qt Creator构建设置中,将jom并行任务数设为1;或在CMakeLists.txt开头添加
set(CMAKE_JOB_POOLS qml_registration_job_pool=1) - 临时注释掉CMakeLists.txt中的
WIN32_EXECUTABLE TRUE,构建成功后再恢复该配置 - 更新CMake至3.28及以上版本(确保与Qt6.11兼容)
- 清理整个构建目录,重新运行CMake配置后再构建
内容的提问来源于stack exchange,提问作者Tang
相关产品推荐
相关产品推荐

