CMake Qt UIC失败 [英] CMake Qt UIC failed

查看:647
本文介绍了CMake Qt UIC失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在将我的项目从QMake移至CMake,并且我遇到了Qt UIC的问题,该问题试图处理一个不存在的ui文件而不是我要他处理的实际文件。

I'm currently moving my project from QMake to CMake and I'm facing a problem with Qt UIC which try to process an ui file that does not exist instead of the actual file I want him to process.

我有以下架构

.
|___ CMakeLists.txt
|___ MyProject.pro
|___ mainwindow.ui
|___ resource.qrc
|___ source
|    |___ mainwindow.cpp
|    |___ *.cpp
|___ include
|    |___ mainwindow.h
|    |___ *.h

这是我的cmake

cmake_minimum_required(VERSION 3.2)

# Project name
project(project)

# Tell CMake to compile with C++11
set(CMAKE_CXX_STANDARD 11)

# Tell CMake to run moc when needed.
set(CMAKE_AUTOMOC ON)

# Tell CMake to run uic when needed.
set(CMAKE_AUTOUIC ON)

# Tell CMake to run rcc when needed
set(CMAKE_AUTORCC ON)

# Moc generated files are located in the current dir so we need to tell CMake to look for them.
set(CMAKE_INCLUDE_CURRENT_DIR ON)

# Find Qt5
find_package(Qt5 COMPONENTS Widgets Core Gui OpenGL REQUIRED)
# Add Qt5 definitions and includes to build libraries. 
# Widgets add Widgets Core and Gui
add_definitions(${Qt5Widgets_DEFINITIONS})
include_directories(${Qt5Widgets_INCLUDES})

add_definitions(${Qt5OpenGL_DEFINITIONS})
include_directories(${Qt5OpenGL_INCLUDES})


# Find OpenGL
find_package(OpenGL REQUIRED)

# Set include directories
include_directories(${CMAKE_SOURCE_DIR}/include

# Use Qt5 ressources
set(RESOURCE resources.qrc)
# Use Qt5 ui
set(UI mainwindow.ui)

# Adding sources
set(SOURCES
    source/main.cpp
    source/mainwindow.cpp
    source/octree.cpp
    source/mesh.cpp
    source/pgm3d.cpp
    source/glwidget.cpp
    source/camera.cpp
    source/scene.cpp 
    source/light.cpp 
    source/obj.cpp 
    source/alignedbox3f.cpp 
    source/wireboundingbox.cpp

    include/mainwindow.h
    include/utils.h
    include/octree.h
    include/mesh.h
    include/pgm3d.h
    include/glwidget.h
    include/camera.h
    include/scene.h
    include/model3d.h
    include/light.h
    include/obj.h
    include/alignedbox3f.h
    include/wireboundingbox.h)


add_executable(${PROJECT_NAME} ${UI} ${RESOURCE} ${SOURCES} )
target_link_libraries(${PROJECT_NAME} ${Qt5Widgets_LIBRARIES} ${Qt5OpenGL_LIBRARIES} ${OPENGL_LIBRARIES})

我有以下错误:

File '/*/project/source/mainwindow.ui' is not valid
AUTOUIC: error: process for ui_mainwindow.h needed by
 "/*/project/source/mainwindow.cpp"
failed:
File '/*/project/source/mainwindow.ui' is not valid

此错误是完全合乎逻辑的,因为我的源文件夹不包含ui文件。我尝试包装ui而不是使用autouic,它也不起作用。

This error is perfectly logical since my source folder does not contain the ui file. I've tried to wrap the ui instead of using autouic and it didn't work either.

推荐答案

AUTOUIC 属性目标(在创建目标时由变量 CMAKE_AUTOUIC 设置)定义生成器的行为-当 AUTOUIC 属性时启用后,CMake将扫描源文件以获取ui文件的内容(例如 #include ui _ *。h #include< ui _ *。h> ),并会使用 uic 工具自动对其进行处理。

在CMake 3.9中添加了另一个目标属性 AUTOUIC_SEARCH_PATHS 。已经在此处提出了类似的问题。

The AUTOUIC property of the target (which is set from the variable CMAKE_AUTOUIC when the target is created) defines behavior of generator - when AUTOUIC property is enabled CMake will scan source files for the includes of ui files (like #include "ui_*.h" or #include <ui_*.h>) and will automatically process them with uic tool.
In CMake 3.9 another target property was added AUTOUIC_SEARCH_PATHS. Similar question was already asked here.

您的另一种选择是禁用 AUTOUIC 并使用 qt5_wrap_ui 以及UI文件的完整路径:

Another option for you would be to disable AUTOUIC and use qt5_wrap_ui with full path to the UI file:

set(CMAKE_AUTOUIC OFF)
set(UI ${CMAKE_CURRENT_LIST_DIR}/mainwindow.ui)
...
qt5_wrap_ui(UI_HEADERS ${UI})
add_executable(${PROJECT_NAME} ${UI_HEADERS} ${RESOURCE} ${SOURCES} )

这篇关于CMake Qt UIC失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆