Qt CMake抱怨找不到autouic文件

Qt CMake抱怨找不到autouic文件,qt,cmake,qt5,Qt,Cmake,Qt5,我正在尝试使用automoc和autouic在子目录中创建一个“HelloWorld” 我有一个主目录 cmake_minimum_required(VERSION 3.1.0) project(helloworld) set(CMAKE_AUTOMOC ON) set(CMAKE_AUTORCC ON) set(CMAKE_AUTOUIC ON) if(CMAKE_VERSION VERSION_LESS "3.7.0") set(CMAKE_INCLUDE_CURRENT_DI

我正在尝试使用automoc和autouic在子目录中创建一个“HelloWorld”

我有一个主目录

cmake_minimum_required(VERSION 3.1.0)

project(helloworld)

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

if(CMAKE_VERSION VERSION_LESS "3.7.0")
    set(CMAKE_INCLUDE_CURRENT_DIR ON)
endif()

find_package(Qt5 COMPONENTS Widgets REQUIRED)

add_subdirectory(main)
add_subdirectory(QtGUI)         
和在main子目录中

add_executable(helloworld
    main.cpp
)

include_directories(
        include
        ../QtGUI/include
)

target_link_libraries(helloworld libQtGUI ) 

在文件QtGUI/CMakeLists.txt中

set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)

#set(AUTOUIC_SEARCH_PATHS  forms)
file(GLOB_RECURSE QOBJECT_SOURCES
    dialog.cpp
)


include_directories(
      ${Qt5Widgets_INCLUDE_DIRS}
      ${CMAKE_BINARY_DIR}
      include
      forms
)

ADD_LIBRARY(libQtGUI ${QOBJECT_SOURCES} )

file(GLOB_RECURSE HEADERS_TO_MOC include/ *.h)
qt5_wrap_cpp(PROCESSED_MOCS
             ${HEADERS_TO_MOC}
             TARGET libQtGUI
             OPTIONS --no-notes) # Don't display a note for the headers which don't produce a moc_*.cpp

target_sources(libQtGUI PRIVATE ${PROCESSED_MOCS}) # This adds generated moc cpps to target


# Use the Widgets module from Qt 5.
target_link_libraries(libQtGUI Qt5::Widgets )

set_target_properties(libQtGUI PROPERTIES OUTPUT_NAME QtGUI
                      )

target_include_directories(libQtGUI PUBLIC
      ${Qt5Widgets_INCLUDE_DIRS}
  $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
)
警告。当我尝试使用AUTOUIC时,我收到一个错误:

fatal error: ui_dialog.h: No such file or directory
 #include "ui_dialog.h"
我错了什么? 根据文件,

"If a preprocessor #include directive is found which matches <path>ui_<basename>.h, and a <basename>.ui file exists, then uic will be executed to generate the appropriate file. "
“如果找到与ui.h匹配的预处理器#include指令,并且存在一个.ui文件,则将执行uic以生成相应的文件。”
我希望生成表单/ui_dialog.h

(我有QtGUI和QtGUI/forms中的dialog.ui文件)


对话
0
0
400
300
对话
150
60
89
25
开始
280
60
89
25
停止
20
60
121
31

用户界面文件是在${CMAKE\u CURRENT\u BINARY\u DIR}中生成的,而不是${CMAKE\u BINARY\u DIR}-因此,请包含此路径并查看它是否有效。

我不认为有理由有重复的用户界面文件;看起来第一个用于生成,但第二个应该存在。然后,解决

  • UI问题,从QtGUI文件夹中删除dialog.UI(仅在“窗体”子文件夹中保留UI文件)
  • 警告是正常的,因为您在CPP文件中没有这些保留字,即,您的CPP没有生成任何内容;参考文档位于“源文件处理”部分。只需删除包含的“dialog.moc”。它将按预期工作

  • 现在它在编译和运行时没有出现警告/问题。

    对不起,我看不到任何更改。ui\u dialog.h是否确实在生成树中的某个位置生成?什么时候是-具体在哪里?
    #ifndef DIALOG_H
    #define DIALOG_H
    
    #include <QDialog>
    #include <QString>
    //#include "mythread.h"
    
    namespace Ui {
    class Dialog;
    }
    
    class Dialog : public QDialog
    {
        Q_OBJECT
    
    public:
        explicit Dialog(QWidget *parent = 0);
        virtual ~Dialog();
    private:
        Ui::Dialog *ui;
    };
    
    #endif // DIALOG_H
    
    The file includes the moc file "dialog.moc", but does not contain a Q_OBJECT, Q_GADGET or Q_NAMESPACE macro.
    
    fatal error: ui_dialog.h: No such file or directory
     #include "ui_dialog.h"
    
    "If a preprocessor #include directive is found which matches <path>ui_<basename>.h, and a <basename>.ui file exists, then uic will be executed to generate the appropriate file. "
    
    <?xml version="1.0" encoding="UTF-8"?>
    <ui version="4.0">
     <class>Dialog</class>
     <widget class="QDialog" name="Dialog">
      <property name="geometry">
       <rect>
        <x>0</x>
        <y>0</y>
        <width>400</width>
        <height>300</height>
       </rect>
      </property>
      <property name="windowTitle">
       <string>Dialog</string>
      </property>
      <widget class="QPushButton" name="StartButton">
       <property name="geometry">
        <rect>
         <x>150</x>
         <y>60</y>
         <width>89</width>
         <height>25</height>
        </rect>
       </property>
       <property name="text">
        <string>Start</string>
       </property>
      </widget>
      <widget class="QPushButton" name="StopButton">
       <property name="geometry">
        <rect>
         <x>280</x>
         <y>60</y>
         <width>89</width>
         <height>25</height>
        </rect>
       </property>
       <property name="text">
        <string>Stop</string>
       </property>
      </widget>
      <widget class="QTextBrowser" name="label">
       <property name="geometry">
        <rect>
         <x>20</x>
         <y>60</y>
         <width>121</width>
         <height>31</height>
        </rect>
       </property>
      </widget>
     </widget>
     <resources/>
     <connections/>
    </ui>