Qt 5 migration - Cannot open include file: 'ui_mainwindow.h'

前端 未结 4 1620
灰色年华
灰色年华 2021-01-18 22:53

I\'m trying to migrate a simple project to Qt 5. The project was originally written for Qt 4, and it compiles fine there.

When compiling with Qt 5, however, I\'m get

相关标签:
4条回答
  • 2021-01-18 23:28

    I had this error when I used cmake instead of qmake to build my project, and I solved it in cmake by adding:

    FILE(GLOB UIs *.ui)
    # to generate header files for .ui files
    qt5_wrap_ui(UI_HEADERS  ${UIs})
    
    0 讨论(0)
  • 2021-01-18 23:35

    What worked for me in the end was deleting both the Debug and Release build folders. What is strange is that I hadn't copied them initially, so I have no idea why it helped deleting them after they were first created.

    But if anyone has this problem, try deleting the Debug and Release folders, as well as the .user file. This should force Qt Creator to reconfigure your project.

    0 讨论(0)
  • 2021-01-18 23:37

    I had the same problem; solved cleaning the project (From Qt->Build) and adding:

    SET(CMAKE_INCLUDE_CURRENT_DIR ON)
    

    As an example, this is my CMakeLists.txt working well:

    #Specify the minimum version of CMake (3.1 is currently recommended by Qt)
    cmake_minimum_required(VERSION 3.1)
    
    # Specify project title
    project(challenge_MarcoRuiz)
    
    # To automatically run MOC when building (Meta Object Compiler)
    set(CMAKE_AUTOMOC ON)
    
    # To automatically run UIC when building (User Interface Compiler)
    set(CMAKE_AUTOUIC ON)
    
    # To automatically run RCC when building (Resource Compiler)
    set(CMAKE_AUTORCC ON)
    
    # Specify OpenCV folder, and take care of dependencies and includes
    find_package(OpenCV REQUIRED)
    include_directories(${OpenCV_INCLUDE_DIRS})
    
    # Take care of Qt dependencies
    find_package(Qt5 COMPONENTS Core Gui Widgets REQUIRED)
    
    ## 
    SET(CMAKE_INCLUDE_CURRENT_DIR ON)
    
    # add required source, header, ui and resource files
    add_executable(${PROJECT_NAME} "main.cpp" "mainwindow.h" "mainwindow.cpp" "mainwindow.ui" ${UI_HEADERS})
    
    # link required libs
    target_link_libraries(${PROJECT_NAME} Qt5::Core Qt5::Gui Qt5::Widgets ${OpenCV_LIBS} ${UI_HEADERS})
    
    0 讨论(0)
  • 2021-01-18 23:38

    Well it is very strange and patience testing error,it happened to me as well a few days ago when my working code start showing this error,am not sure but for me it was due to the fact that my mainwindow.ui and mainwindow.qrc was not compiled so I take the following steps

    1. compiled the mainwindow.ui (right click on mainwindow.ui file in the solution Explorer and select compile )and it gave something C:\Qt1\5.9\msvc2017_64\lib\rcc.exe which was missing in that destination,so I went to C:\Qt1\5.9\msvc2015_64\bin,copy and paste rcc.exe from C:\Qt1\5.9\msvc2015_64\bin to C:\Qt1\5.9\msvc2017_64\lib
    2. compile these two file once again and built the code again
    3. no error that is it .
    0 讨论(0)
提交回复
热议问题