Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QT : header in .ui files

Tags:

cmake

qt

I want to know how to make <header> in files.ui works with cmake for custom widgets.

I've CMakeLists like this :

cmake_minimum_required(VERSION 3.0.0 FATAL_ERROR)

project(qtelec C CXX)

set(CMAKE_PREFIX_PATH $ENV{HOME}/Qt5.6.0/5.6/gcc_64)
set(SRC_BASE_DIR "../../../qtelec")
set(COREALPI_BUILD_DIR "../../../../corealpi/build")

set(CMAKE_AUTOMOC ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTORCC ON)

find_package(Qt5Widgets REQUIRED)

file(GLOB_RECURSE SRC_FILES 
    ${SRC_BASE_DIR}/src/*.h 
    ${SRC_BASE_DIR}/src/*.cpp
)

link_directories(${COREALPI_BUILD_DIR}/elec)
link_directories(${COREALPI_BUILD_DIR}/elec/core)

add_library(qtelec SHARED
    ${SRC_FILES}
)

add_subdirectory(${SRC_BASE_DIR}/../platform/cmake/qtutils ${CMAKE_BINARY_DIR}/qtutils)  
include_directories(${SRC_BASE_DIR}/../external/qtpropertybrowser/latest/src)
include_directories(${SRC_BASE_DIR}/../qtutils/src)
#include_directories(${SRC_BASE_DIR}/src/widgets)
include_directories(${COREALPI_BUILD_DIR}/../include/ca)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")

target_link_libraries(qtelec qtpropertybrowser elec core qtutils Qt5::Widgets)

cmake .. works but cmake --build . give me the following error :

[ 65%] Building CXX object CMakeFiles/qtelec.dir/home/mea/workspace/repos/qtelec/qtelec/src/forms/conversionform.cpp.o
In file included from /home/mea/workspace/repos/qtelec/qtelec/src/forms/conversionform.cpp:2:0:
/home/mea/workspace/repos/qtelec/build/ui_conversionform.h:18:40: fatal error: ../widgets/canecoboxwidget.h: Aucun fichier ou dossier de ce type
compilation terminated.

If I look in my conversionform.ui I've something like that (and in other files.ui too) :

<customwidgets>
  <customwidget>
   <class>CanecoBoxWidget</class>
   <extends>QWidget</extends>
   <header>../widgets/canecoboxwidget.h</header>
   <container>1</container>
  </customwidget>
</customwidgets>

But the problem is my ui_generated files are in my build folder, so when cmake attempt to find path ../widgets/ he doesn't exist. Here is my folder structure :

├── build
├── qtelec
│   ├── src
│        └── *.h
│        └── *.cpp
│        └── editors
│              └── *.h
│              └── *.cpp
│              └── *.ui
│        └── forms
│              └── *.h
│              └── *.cpp
│              └── *.ui
│        └── widgets
│              └── *.h
│              └── *.cpp
│              └── *.ui
├── cmake/CMakelists.txt

The only solution I found is to include directory with include_directories(${SRC_BASE_DIR}/src/widgets).

But I think there is other way in CMake or QT to make it work without additional include ?

In .pro file, there si no need to include this folder.

Can you help me to find a solution please ?

If you want more information, I can give it.

Thanks for help.

like image 694
Algorys Avatar asked Nov 08 '22 15:11

Algorys


1 Answers

Files generated from .ui file are placed in ${CMAKE_BINARY_DIR}, not ${CMAKE_SOURCE_DIR}. In you case it is /home/mea/workspace/repos/qtelec/build/. As you can see, there is no /home/mea/workspace/repos/qtelec/build/../widgets/canecoboxwidget.h.

The proper solution there is to use qt_wrap_ui command, i guess.

like image 74
arrowd Avatar answered Nov 15 '22 06:11

arrowd