Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/135.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ Qt5和Cmake链接QApplication标头错误_C++_Cmake_Qt5_Qwidget_Qapplication - Fatal编程技术网

C++ Qt5和Cmake链接QApplication标头错误

C++ Qt5和Cmake链接QApplication标头错误,c++,cmake,qt5,qwidget,qapplication,C++,Cmake,Qt5,Qwidget,Qapplication,我正在尝试将cmake与我的一个使用QApplication的Qt项目联系起来。 我在构建项目时遇到了这个错误 Cannot open include file: 'QApplication': No such file or directory 我只在.cpp文件中使用QApplication和QWebEngineeWidget,在头文件中使用QDir main.h #ifndef MAIN_H #define MAIN_H #include <QDir> QUrl getl

我正在尝试将cmake与我的一个使用QApplication的Qt项目联系起来。 我在构建项目时遇到了这个错误

Cannot open include file: 'QApplication': No such file or directory
我只在.cpp文件中使用QApplication和QWebEngineeWidget,在头文件中使用QDir

main.h

#ifndef MAIN_H
#define MAIN_H

#include <QDir>

QUrl getlink(){

    QUrl url = QUrl::fromLocalFile(QDir::currentPath();

    return url;

}


#endif // MAIN_H
我知道我可能不需要其他链接的LIB,但我将它们保留在那里以备将来发展

无论如何,当我在目标链接中为QWebEngineView添加Qt5::WebEngineWidget时,效果很好,但当我为QApplication添加Qt5::Widget时,它似乎无法找到文件,我不知道为什么


你知道问题出在哪里吗?

正如@vre在评论中提到的,你从来没有将你的GUI应用程序链接到Qt5。下面是您发布的CMakeLists.txt的固定版本


您应该将target_link_librariesSIM_APP Qt5::gui或target_link_librariesSIM_APP QtSimAppProjectLib添加到CMake文件中。否则,SIM_应用程序目标不知道在哪里可以找到添加源的包含。我按照您的建议执行了操作,但出现了此错误。无法为此项目未生成的目标SIM_应用程序指定链接库。SIM_应用程序确实找到了其他所有内容的包含QApplication是唯一找不到的应用程序。您将目标链接放在哪里了?它必须在add_可执行文件之后,而不是之前。这些命令取决于位置。感谢@vre和Paul,我添加了这些更改,现在可以使用了。
    #include <QApplication>
    #include <QWebEngineView>
    #include "main.h"

int main(int argc, char *argv[])
{
    QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
    QApplication app(argc, argv);

    QWebEngineView view;
    view.setUrl(getlink());
    view.resize(1524, 850);
    view.show();

   return app.exec();

}
if (ENABLE_QT_SimApp_GUI)

find_package(qtlibs)

find_package(SimApp)
if (NOT SimApp_FOUND)
    message(FATAL_ERROR "Could not find SimApp")
endif(NOT SimApp_FOUND)

set(CMAKE_PREFIX_PATH ${PREFIX_PATH})
message(STATUS "CMAKE_PREFIX_PATH" ${CMAKE_PREFIX_PATH})

find_package(Qt5 REQUIRED COMPONENTS Widgets Core Gui Sql PrintSupport WebEngineWidgets)

qt5_wrap_cpp(QtSimAppProjectLib_hdr_moc ${QtSimAppProjectLib_hdr})
qt5_wrap_ui(QtSimAppProjectLib_ui_uic ${QtSimAppProjectLib_ui})
qt5_add_resources(QtSimAppProjectLib_qrc_rcc ${QtSimAppProjectLib_qrc})

include_directories (${PROJECT_SOURCE_DIR})
include_directories (${PROJECT_BINARY_DIR})

add_library (QtSimAppProjectLib STATIC ${QtSimAppProjectLib_src} ${QtSASQProjectLib_hdr_moc} ${QtSASQProjectLib_ui_uic})

target_link_libraries (QtSimAppProjectLib
        Qt5::Core
        Qt5::Gui
        Qt5::Widgets
        Qt5::Sql
        Qt5::PrintSupport
        Qt5::WebEngineWidgets)

#WIN32 to suppress the console window under Windows
add_executable(SIM_APP WIN32 ${QtSimAppProjectLib_src} ${QtSimAppProjectLib_qrc_rcc})

    if (ENABLE_COPY_QT_LIBS AND WIN32)
        find_package(qtdlls)
    endif(ENABLE_COPY_QT_LIBS AND WIN32)

endif (ENABLE_QT_SimApp_GUI)
if (ENABLE_QT_SimApp_GUI)

find_package(qtlibs)

find_package(SimApp)
if (NOT SimApp_FOUND)
    message(FATAL_ERROR "Could not find SimApp")
endif(NOT SimApp_FOUND)

set(CMAKE_PREFIX_PATH ${PREFIX_PATH})
message(STATUS "CMAKE_PREFIX_PATH" ${CMAKE_PREFIX_PATH})

find_package(Qt5 REQUIRED COMPONENTS Widgets Core Gui Sql PrintSupport WebEngineWidgets)

qt5_wrap_cpp(QtSimAppProjectLib_hdr_moc ${QtSimAppProjectLib_hdr})
qt5_wrap_ui(QtSimAppProjectLib_ui_uic ${QtSimAppProjectLib_ui})
qt5_add_resources(QtSimAppProjectLib_qrc_rcc ${QtSimAppProjectLib_qrc})

include_directories (${PROJECT_SOURCE_DIR})
include_directories (${PROJECT_BINARY_DIR})

add_library (QtSimAppProjectLib STATIC ${QtSimAppProjectLib_src} ${QtSASQProjectLib_hdr_moc} ${QtSASQProjectLib_ui_uic})

target_link_libraries (QtSimAppProjectLib
        Qt5::Core
        Qt5::Gui
        Qt5::Widgets
        Qt5::Sql
        Qt5::PrintSupport
        Qt5::WebEngineWidgets)

#WIN32 to suppress the console window under Windows
add_executable(SIM_APP WIN32 ${QtSimAppProjectLib_src} ${QtSimAppProjectLib_qrc_rcc})

# use one of the following target_link_libraries() calls
target_link_libraries(SIM_APP Qt5::Core Qt5::Gui Qt5::Widgets)
# target_link_libraries(SIM_APP QtSimAppProjectLib)

if (ENABLE_COPY_QT_LIBS AND WIN32)
    find_package(qtdlls)
endif(ENABLE_COPY_QT_LIBS AND WIN32)

endif (ENABLE_QT_SimApp_GUI)