简体   繁体   中英

how to make GUI Qt project with cmake in Qt Creator with .ui files

I want to created a project that uses cmake as it's build system sn QTCreator

.
├── CMakeLists.txt
├── CMakeLists.txt.user
├── main.cpp
├── notepad.cpp
├── notepad.h
└── notepad.ui

here is my cmake file:-

cmake_minimum_required(VERSION 2.8)
project(Notepad)

set(CMAKE_CXX_FLAGS " ${CMAKE_CXX_FLAGS} -Wall -Wextra -Wpedantic -std=gnu++14")

find_package(Qt5Widgets REQUIRED)

set(CMAKE_VERBOSE_MAKEFILE ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)

set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)

add_executable(${PROJECT_NAME} main.cpp notepad.cpp)
target_link_libraries(Notepad Qt5::Widgets)

When I try to build it I get following error:-

AutoUic subprocess error
------------------------
uic failed for
  "/home/jucyref/Development/C++/Test/notepad/notepad.ui"
included by
  "/home/jucyref/Development/C++/Test/notepad/notepad.cpp"

Command
-------
/usr/bin/uic -o /home/jucyref/Development/C++/Test/build-notepad-C_C-Default/Notepad_autogen/include/ui_notepad.h /home/jucyref/Development/C++/Test/notepad/notepad.ui

Output
------
File '/home/jucyref/Development/C++/Test/notepad/notepad.ui' is not valid

.QtCreator's Design mode.it is disabled by default .what should I do. I am not very familiar with cmake and qt

You are missing UI headers in add_executable

more details on https://wiki.qt.io/Using_CMake_build_system

set ( SOURCES
..cpp
)

set ( MOC_HEADERS
 ..h
)

set ( UIS
 notepad.ui
)

set ( RESOURCES
 ..qrc
)
QT5_WRAP_UI( UI_HEADERS ${UIS} )

add_executable( PROJECT_NAME ${SOURCES} ${MOC_SRCS} ${RES_SOURCES} ${UI_HEADERS} )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM