CMake + Qt6: Unable to Find <QNetworkAccessManager> header
-
I'm encountering an unusual issue with a CMake + Qt6 project. In my CMakeLists.txt, I have configured Qt6 Network like this:
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets) find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core Gui Widgets SerialPort PrintSupport Network OpenGL OpenGLWidgets LinguistTools ) set(SRC main.cpp controller/controller.cpp controller/product.cpp controller/serialportmanager.cpp core/eventhub.cpp core/observer.cpp views/configview.cpp views/dataview.cpp views/firmwareupgradeview.cpp views/mainwindow.cpp views/viewbasewidget.cpp views/serialportview.cpp global.h controller/controller.h controller/product.h controller/serialportmanager.h core/eventhub.h core/observer.h views/configview.h views/dataview.h views/firmwareupgradeview.h views/mainwindow.h views/viewbasewidget.h views/serialportview.h views/configview.ui views/dataview.ui views/firmwareupgradeview.ui views/mainwindow.ui views/serialportview.ui ) if(${QT_VERSION_MAJOR} GREATER_EQUAL 6) qt_add_executable(${CMAKE_PROJECT_NAME} MANUAL_FINALIZATION "${SRC}" "${CMAKE_SOURCE_DIR}/resource/res.qrc" views/tempins.h views/tempins.cpp views/tempins.ui ) endif() target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::Widgets Qt${QT_VERSION_MAJOR}::Gui Qt${QT_VERSION_MAJOR}::SerialPort Qt${QT_VERSION_MAJOR}::PrintSupport Qt${QT_VERSION_MAJOR}::Network Qt${QT_VERSION_MAJOR}::OpenGL Qt${QT_VERSION_MAJOR}::OpenGLWidgets widgets )
I tried
#include <QNetworkAccessManager>
in controller.cpp, but it fails to find the header file. However, when I include it in other source files, like firmwareupgradeview.cpp, it works fine, I only know controller.cpp is having this issue. I've already tried cleaning and rebuilding the project, as well as checking the include paths, but nothing has resolved the problem. -
I'm encountering an unusual issue with a CMake + Qt6 project. In my CMakeLists.txt, I have configured Qt6 Network like this:
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets) find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core Gui Widgets SerialPort PrintSupport Network OpenGL OpenGLWidgets LinguistTools ) set(SRC main.cpp controller/controller.cpp controller/product.cpp controller/serialportmanager.cpp core/eventhub.cpp core/observer.cpp views/configview.cpp views/dataview.cpp views/firmwareupgradeview.cpp views/mainwindow.cpp views/viewbasewidget.cpp views/serialportview.cpp global.h controller/controller.h controller/product.h controller/serialportmanager.h core/eventhub.h core/observer.h views/configview.h views/dataview.h views/firmwareupgradeview.h views/mainwindow.h views/viewbasewidget.h views/serialportview.h views/configview.ui views/dataview.ui views/firmwareupgradeview.ui views/mainwindow.ui views/serialportview.ui ) if(${QT_VERSION_MAJOR} GREATER_EQUAL 6) qt_add_executable(${CMAKE_PROJECT_NAME} MANUAL_FINALIZATION "${SRC}" "${CMAKE_SOURCE_DIR}/resource/res.qrc" views/tempins.h views/tempins.cpp views/tempins.ui ) endif() target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::Widgets Qt${QT_VERSION_MAJOR}::Gui Qt${QT_VERSION_MAJOR}::SerialPort Qt${QT_VERSION_MAJOR}::PrintSupport Qt${QT_VERSION_MAJOR}::Network Qt${QT_VERSION_MAJOR}::OpenGL Qt${QT_VERSION_MAJOR}::OpenGLWidgets widgets )
I tried
#include <QNetworkAccessManager>
in controller.cpp, but it fails to find the header file. However, when I include it in other source files, like firmwareupgradeview.cpp, it works fine, I only know controller.cpp is having this issue. I've already tried cleaning and rebuilding the project, as well as checking the include paths, but nothing has resolved the problem.@IPlayGenji6 said in CMake + Qt6: Unable to Find <QNetworkAccessManager> header:
only controller.cpp is having this issue
Try
product.cpp
as well, if this also doesn't work, it's most likely because of your directory structure.
Iscontroller/
in your include path? -
@IPlayGenji6 said in CMake + Qt6: Unable to Find <QNetworkAccessManager> header:
only controller.cpp is having this issue
Try
product.cpp
as well, if this also doesn't work, it's most likely because of your directory structure.
Iscontroller/
in your include path?@Pl45m4
I tried, it didn't work. this is my directory structure:D:\QT-PROJECTS\PROJECT1\SRC │ CMakeLists.txt │ global.h │ main.cpp │ ├─controller │ controller.cpp │ controller.h │ product.cpp │ product.h │ serialportmanager.cpp │ serialportmanager.h │ turntable.cpp │ turntable.h │ ├─core │ eventhub.cpp │ eventhub.h │ observer.cpp │ observer.h │ ├─views │ calibrationview.cpp │ calibrationview.h │ calibrationview.ui │ configview.cpp │ configview.h │ configview.ui │ dataview.cpp │ dataview.h │ dataview.ui │ firmwareupgradeview.cpp │ firmwareupgradeview.h │ firmwareupgradeview.ui │ mainwindow.cpp │ mainwindow.h │ mainwindow.ui │ serialportview.cpp │ serialportview.h │ serialportview.ui │ tempins.cpp │ tempins.h │ tempins.ui │ turntableview.cpp │ turntableview.h │ turntableview.ui │ viewbasewidget.cpp │ viewbasewidget.h │ viewbasewidget.ui
and cmake
set(INC "${CMAKE_CURRENT_SOURCE_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}/controller" "${CMAKE_CURRENT_SOURCE_DIR}/core" "${CMAKE_CURRENT_SOURCE_DIR}/views" ) target_include_directories(${CMAKE_PROJECT_NAME} PRIVATE "${CMAKE_SOURCE_DIR}/include" "${INC}" )
-
@IPlayGenji6 said in CMake + Qt6: Unable to Find <QNetworkAccessManager> header:
only controller.cpp is having this issue
Try
product.cpp
as well, if this also doesn't work, it's most likely because of your directory structure.
Iscontroller/
in your include path?@Pl45m4
I used#include <QtNetwork/QNetworkAccessManager>
in controller.cpp and resolved the issue, but I didn't need to add the pathQtNetwork/
in firmwareupgradeview.cpp. why that is? -
@Pl45m4
I used#include <QtNetwork/QNetworkAccessManager>
in controller.cpp and resolved the issue, but I didn't need to add the pathQtNetwork/
in firmwareupgradeview.cpp. why that is?@IPlayGenji6
Have a look carefully at the actual compiler statements generated for these two source files during build. So far as I know include paths are not passed by setting environment variables so you should see a difference in the-I...
options, else it would be inexplicable/something deeper.This assumes " it fails to find the header file" is an actual error generated during compilation? If it's only while editing inside Creator then it's from the Code Model only, and that sometimes gets stuff wrong for unknown reasons.
-
I IPlayGenji6 has marked this topic as solved on