Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Unable to compile, ui header never found. (Qt6, Clion, Windows)
Forum Updated to NodeBB v4.3 + New Features

Unable to compile, ui header never found. (Qt6, Clion, Windows)

Scheduled Pinned Locked Moved Unsolved General and Desktop
12 Posts 4 Posters 1.5k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • SGaistS Offline
    SGaistS Offline
    SGaist
    Lifetime Qt Champion
    wrote on last edited by
    #2

    Hi and welcome to devnet,

    Looking at the autouic documentation, it think you either have to add gui/ in front of ui_MonkeyWindow.h of your include or add gui to the autouic search paths.

    Interested in AI ? www.idiap.ch
    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

    GAlbertG 1 Reply Last reply
    2
    • SGaistS SGaist

      Hi and welcome to devnet,

      Looking at the autouic documentation, it think you either have to add gui/ in front of ui_MonkeyWindow.h of your include or add gui to the autouic search paths.

      GAlbertG Offline
      GAlbertG Offline
      GAlbert
      wrote on last edited by
      #3

      Nevermind, thanks a lot for your help, I was about to ask you if I wasn't including gui to the autouic search paths already with this

      set(CMAKE_AUTOUIC_SEARCH_PATHS ${CMAKE_CURRENT_SOURCE_DIR}/gui)
      

      But in fact what im doing is adding /src/gui/ as the autouic search paths ... so unless you can tell me how to include /gui/ ill have to keep the .ui and .cpp file in the same folder.

      Also, now that it does find the ui header, it says that there's this error:

      undefined reference to `vtable for MonkeyWindow'
      

      If I got it correctly its because I forgot to implement a virtual function ? What could I be missing in the .cpp ?

      1 Reply Last reply
      0
      • GAlbertG GAlbert

        Hello, recently tried to convert my shell app into a GUI app with Qt, but had some problems at build time.
        (This app is a model kit collection manager and its name is MonkeyModelKit, thus the names of the files you'll see down there...)

        Currently I get this error:

        C:/Users/Albert/Documents/COALAs/monkey-model-kit/src/gui/MonkeyWindow.cpp:9:10: fatal error: ui_MonkeyWindow.h: No such file or directory
            9 | #include "ui_MonkeyWindow.h"
              |          ^~~~~~~~~~~~~~~~~~~
        

        Here's what my project directory tree looks like more or less (only kept the code files and removed resources):
        b5342bfe-0415-432c-abc6-a3bfa6a851ba-smwzwqcbfgzc1.png

        The Cmakelists looks like this:

        cmake_minimum_required(VERSION 3.28)
        project(MonkeyModelKit LANGUAGES CXX)
        
        set(CMAKE_PREFIX_PATH "C:/Qt/6.6.0/mingw_64")
        set(CMAKE_AUTOMOC ON)
        set(CMAKE_AUTORCC ON)
        set(CMAKE_AUTOUIC ON)
        set(CMAKE_AUTOUIC_SEARCH_PATHS ${CMAKE_CURRENT_SOURCE_DIR}/gui)
        find_package(Qt6 COMPONENTS
                Core
                Gui
                Widgets
                REQUIRED)
        
        set(SOURCES
                src/main.cpp
                src/StringManipulation.cpp
                src/run/MonkeyShell.cpp
                src/run/MonkeyManager.cpp
                src/run/MonkeyFile.cpp
                src/col/MonkeyModel.cpp
                src/col/MonkeySession.cpp
                src/col/MonkeyCollection.cpp
                src/gui/MonkeyWindow.cpp
                # Add more source files as needed
        )
        
        set(UI_FILES
                gui/MonkeyWindow.ui
                # Add more UI files as needed
        )
        
        qt6_wrap_ui(UI_HEADERS ${UI_FILES})
        
        include_directories(
                include/
                include/col
                include/run
                include/gui
                /gui
        )
        
        add_executable(MonkeyModelKit WIN32
                ${SOURCES}
                ${UI_FILES}
                ${UI_HEADERS}
        )
        target_include_directories(MonkeyModelKit
                PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/gui
        )
        
        target_link_libraries(MonkeyModelKit PRIVATE Qt6::Widgets)
        

        And the .cpp class:

        #include "MonkeyWindow.hpp"
        #include "ui_MonkeyWindow.h"
        MonkeyWindow::MonkeyWindow(QWidget *parent) :
            QMainWindow(parent), ui(new Ui::MonkeyWindow) {
            ui->setupUi(this);
        }
        MonkeyWindow::~MonkeyWindow() {
            delete ui;
        }
        #include "MonkeyWindow.hpp"
        #include "ui_MonkeyWindow.h"
        
        MonkeyWindow::MonkeyWindow(QWidget *parent) :
            QMainWindow(parent), ui(new Ui::MonkeyWindow) {
            ui->setupUi(this);
        }
        
        MonkeyWindow::~MonkeyWindow() {
            delete ui;
        }
        

        I don't really know what to do right now, its been a few weeks that I simply can not build my project and can not start learning how Qt works at all...

        The only way to make it work is to have all the MonkeyWindow files (.cpp, .hpp and .ui) in the same subdirectory and then everything works all fine. I saw somewhere that the new cpp standard says to not separate header files and source files but I find this super messy, is this right (technically would fix my problem but would make working on the proj so hard) ?

        Thanks for the help ...

        Christian EhrlicherC Offline
        Christian EhrlicherC Offline
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on last edited by Christian Ehrlicher
        #4

        @GAlbert said in Unable to compile, ui header never found. (Qt6, Clion, Windows):

        qt6_wrap_ui(UI_HEADERS ${UI_FILES})

        Why? Either use autouic or do it manually. Remove this.

        What could I be missing in the .cpp ?

        Maybe the Q_OBJECT macro in the header.

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        GAlbertG 1 Reply Last reply
        0
        • Christian EhrlicherC Christian Ehrlicher

          @GAlbert said in Unable to compile, ui header never found. (Qt6, Clion, Windows):

          qt6_wrap_ui(UI_HEADERS ${UI_FILES})

          Why? Either use autouic or do it manually. Remove this.

          What could I be missing in the .cpp ?

          Maybe the Q_OBJECT macro in the header.

          GAlbertG Offline
          GAlbertG Offline
          GAlbert
          wrote on last edited by
          #5

          Why? Either use autouic or do it manually. Remove this.

          Yup, didn't know that, learnt it yesterday and fixed my "header not found" problem by using ${CMAKE_CURRENT_SOURCE_DIR}/gui as a autouic parameter.

          Maybe the Q_OBJECT macro in the header.

          Nah, I already have the Q_OBJECT macro in the header :/
          Here it is:

          #include <QMainWindow>
          
          QT_BEGIN_NAMESPACE
          namespace Ui { class MonkeyWindow; }
          QT_END_NAMESPACE
          
          class MonkeyWindow : public QMainWindow {
          Q_OBJECT
          
          public:
              explicit MonkeyWindow(QWidget *parent = nullptr);
              ~MonkeyWindow() override;
          
          private:
              Ui::MonkeyWindow *ui;
          };
          
          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #6

            Nuke the build folder and start again, it might be stale from all the tests you did to get uic sorted out.

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            GAlbertG 1 Reply Last reply
            0
            • SGaistS SGaist

              Nuke the build folder and start again, it might be stale from all the tests you did to get uic sorted out.

              GAlbertG Offline
              GAlbertG Offline
              GAlbert
              wrote on last edited by GAlbert
              #7

              @SGaist Just did, still got hit with the

              C:\Users\Albert\AppData\Local\Programs\CLion\bin\mingw\bin/ld.exe: CMakeFiles/MonkeyModelKit.dir/src/gui/MonkeyWindow.cpp.obj:MonkeyWindow.c:(.rdata$.refptr._ZTV12MonkeyWindow[.refptr._ZTV12MonkeyWindow]+0x0): undefined reference to `vtable for MonkeyWindow'
              collect2.exe: error: ld returned 1 exit status
              ninja: build stopped: subcommand failed.
              

              😢

              By the way, is there a way for me to get exactly what this refptr is that is not defined ? I assume if I find what ".refptr._ZTV12MonkeyWindow]+0x0" is I might be able to define it ? Or am I too C based pointer pilled ?

              1 Reply Last reply
              0
              • Christian EhrlicherC Offline
                Christian EhrlicherC Offline
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote on last edited by Christian Ehrlicher
                #8

                Where is your header file located? Normally AUTOMOC should parse your header and generate & compile the corresponding moc_MonkeyWindow.cpp
                Please add #include "moc_MonkeyWindow.cpp" at the end of your MonkeyWindow.cpp to see if this fixes the problem. Or add MonkeyWindow.hpp to your SOURCES to see if this helps (it should according the sources).

                Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                Visit the Qt Academy at https://academy.qt.io/catalog

                GAlbertG 1 Reply Last reply
                0
                • Christian EhrlicherC Christian Ehrlicher

                  Where is your header file located? Normally AUTOMOC should parse your header and generate & compile the corresponding moc_MonkeyWindow.cpp
                  Please add #include "moc_MonkeyWindow.cpp" at the end of your MonkeyWindow.cpp to see if this fixes the problem. Or add MonkeyWindow.hpp to your SOURCES to see if this helps (it should according the sources).

                  GAlbertG Offline
                  GAlbertG Offline
                  GAlbert
                  wrote on last edited by
                  #9

                  @Christian-Ehrlicher uhhhm... I think we got our culprit, I ain't finding no "moc_MonkeyWindow.cpp" file in the build dir... the closest file name I could find would be "mocs_compilation.cpp"

                  1 Reply Last reply
                  0
                  • GAlbertG Offline
                    GAlbertG Offline
                    GAlbert
                    wrote on last edited by
                    #10

                    Alright, it looks like the moc file can not be generated if the only way I add headers is by using :

                    include_directories(
                            include/
                            include/col
                            include/run
                            include/gui
                            gui/
                    )
                    

                    What I in fact need to do is :

                    set(HEADERS
                            include/gui/MonkeyWindow.hpp
                    )
                    

                    And manually add all the headers... Unless someone knows how to fix this ill have to add all the headers manually ...

                    1 Reply Last reply
                    0
                    • MoonFeatherM Offline
                      MoonFeatherM Offline
                      MoonFeather
                      wrote on last edited by MoonFeather
                      #11

                      I've solve this problem by copying Qt Creator and docs' CMake configuration.
                      First do include ui_*.h file in the beginning, ignoring error from IDEs:

                      // in my project, the mainwindow.cpp and mainwindow.ui are in same folder
                      #include "./ui_mainwindow.h"
                      

                      Then add CMake options like this, and run cmake.

                      -DCMAKE_PREFIX_PATH=C:\Qt\6.7.2\mingw_64\lib\cmake
                      -DCMAKE_GENERATOR:STRING=Ninja
                      -DQT_QMAKE_EXECUTABLE:FILEPATH=C:/Qt/6.7.2/mingw_64/bin/qmake.exe
                      -DCMAKE_C_COMPILER:FILEPATH=C:/Qt/Tools/mingw1120_64/bin/gcc.exe
                      -DCMAKE_CXX_COMPILER:FILEPATH=C:/Qt/Tools/mingw1120_64/bin/g++.exe
                      -DCMAKE_CXX_FLAGS_INIT:STRING=-DQT_QML_DEBUG
                      # Remember to substitute with real path
                      

                      Finally, run this command:

                      cmake --build <your-build-path> --target all
                      

                      the key is the "--target all" option.
                      you can add this option in CLion by Preference -> CMake -> Cache Variables -> Build options.

                      MoonFeatherM 1 Reply Last reply
                      0
                      • MoonFeatherM MoonFeather

                        I've solve this problem by copying Qt Creator and docs' CMake configuration.
                        First do include ui_*.h file in the beginning, ignoring error from IDEs:

                        // in my project, the mainwindow.cpp and mainwindow.ui are in same folder
                        #include "./ui_mainwindow.h"
                        

                        Then add CMake options like this, and run cmake.

                        -DCMAKE_PREFIX_PATH=C:\Qt\6.7.2\mingw_64\lib\cmake
                        -DCMAKE_GENERATOR:STRING=Ninja
                        -DQT_QMAKE_EXECUTABLE:FILEPATH=C:/Qt/6.7.2/mingw_64/bin/qmake.exe
                        -DCMAKE_C_COMPILER:FILEPATH=C:/Qt/Tools/mingw1120_64/bin/gcc.exe
                        -DCMAKE_CXX_COMPILER:FILEPATH=C:/Qt/Tools/mingw1120_64/bin/g++.exe
                        -DCMAKE_CXX_FLAGS_INIT:STRING=-DQT_QML_DEBUG
                        # Remember to substitute with real path
                        

                        Finally, run this command:

                        cmake --build <your-build-path> --target all
                        

                        the key is the "--target all" option.
                        you can add this option in CLion by Preference -> CMake -> Cache Variables -> Build options.

                        MoonFeatherM Offline
                        MoonFeatherM Offline
                        MoonFeather
                        wrote on last edited by
                        #12

                        Also, for different file path of .ui file, both change CMakeLists.txt:

                        set(PROJECT_SOURCES
                                main.cpp
                                mainwindow.cpp
                                mainwindow.h
                                Form/mainwindow.ui
                        )
                        

                        and the mainwindow.cpp's include path:

                        #include "./Form/ui_mainwindow.h"
                        
                        1 Reply Last reply
                        0

                        • Login

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • Users
                        • Groups
                        • Search
                        • Get Qt Extensions
                        • Unsolved