CMake & QT5 - QT5_WRAP_UI does not generate ui header files

I have a simple CMakeLists.txt that looks like this:

CMAKE_MINIMUM_REQUIRED(VERSION 2.8) PROJECT(calculator) FIND_PACKAGE(Qt5Core) FIND_PACKAGE(Qt5Gui) FIND_PACKAGE(Qt5Widgets) SET(CMAKE_AUTOMOC ON) SET(CMAKE_INCLUDE_CURRENT_DIR ON) SET(calculator_SOURCES main.cpp mainwindow.cpp) SET(calculator_HEADERS mainwindow.h) SET(calculator_FORMS mainwindow.ui) QT5_WRAP_CPP(calculator_HEADERS_MOC ${calculator_HEADERS}) QT5_WRAP_UI(calculator_FORMS_HEADERS ${calculator_FORMS}) ADD_LIBRARY(calculator_CONFIG ${calculator_HEADERS_MOC} ${calculator_FORMS_HEADERS}) QT5_USE_MODULES(calculator_CONFIG Widgets) ADD_EXECUTABLE(calculator ${calculator_SOURCES} ${calculator_CONFIG}) QT5_USE_MODULES(calculator Core Gui Widgets) 

And when I try to build a project using cmake -G "Unix Makefiles" and subsequently make , the console says that ui_mainwindow.h not found. What is the problem? Is this my cmake file?


Full error output:

 [ 22%] Building CXX object CMakeFiles/calculator.dir/mainwindow.cpp.o /home/centurion/Code/cpp/calculator/mainwindow.cpp:2:27: fatal error: ui_mainwindow.h: No such file or directory #include "ui_mainwindow.h" ^ compilation terminated. make[2]: *** [CMakeFiles/calculator.dir/mainwindow.cpp.o] Error 1 make[1]: *** [CMakeFiles/calculator.dir/all] Error 2 make: *** [all] Error 2 
+10
c ++ qt cmake makefile
source share
3 answers
  • Use the lowercase CMake commands. This has been a reasonable agreement for many years.

  • Why are you using both AUTOMOC and qt5_wrap_cpp? AUTOMOC is intended to replace the macro. http://www.cmake.org/cmake/help/v3.0/manual/cmake-qt.7.html#automoc

  • If you are using CMake 2.8.11 or later, do not use qt5_use_modules. I wrote this as a hacked gap until I released CMake 2.8.11. The target_link_libraries command does what qt5_use_modules does, but better and more generally. http://doc-snapshot.qt-project.org/qt5-5.3/cmake-manual.html

  • The library does not have its own sources and is not used. You are clearly โ€œdoing it wrongโ€ here. Move the use of the variable $ {calculator_FORMS_HEADERS} to the source files. Then, after addressing point 2, delete the library.

+1
source share

I worked in the same problem with cmake 3.2.2. Try using

 SET(CMAKE_AUTOUIC ON) 

if ui files are not generated. Maybe the default behavior has changed lately?

+16
source share

I ran into the same problem on Mac OS X. The Ui form header file is not generated.

I solved my problem by creating a .h file using QtDesigner. When changes are made in the ui form, the header file is well generated.

Note: if I add some other ui forms, headers are generated automatically, without the need to manually generate a header file for these other ui.

EDIT: The header file is well generated during the first build, only if it is not used in cpp code.

0
source share

All Articles