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. CMake + Qt6: Unable to Find <QNetworkAccessManager> header

CMake + Qt6: Unable to Find <QNetworkAccessManager> header

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 3 Posters 376 Views
  • 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.
  • I Offline
    I Offline
    IPlayGenji6
    wrote on 7 Nov 2024, 01:28 last edited by IPlayGenji6 11 Jul 2024, 02:03
    #1

    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.

    P 1 Reply Last reply 7 Nov 2024, 01:36
    0
    • I IPlayGenji6
      7 Nov 2024, 01:28

      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.

      P Offline
      P Offline
      Pl45m4
      wrote on 7 Nov 2024, 01:36 last edited by
      #2

      @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.
      Is controller/ in your include path?


      If debugging is the process of removing software bugs, then programming must be the process of putting them in.

      ~E. W. Dijkstra

      I 2 Replies Last reply 7 Nov 2024, 01:55
      0
      • P Pl45m4
        7 Nov 2024, 01:36

        @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.
        Is controller/ in your include path?

        I Offline
        I Offline
        IPlayGenji6
        wrote on 7 Nov 2024, 01:55 last edited by
        #3

        @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}"
        )
        
        1 Reply Last reply
        0
        • P Pl45m4
          7 Nov 2024, 01:36

          @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.
          Is controller/ in your include path?

          I Offline
          I Offline
          IPlayGenji6
          wrote on 7 Nov 2024, 07:14 last edited by
          #4

          @Pl45m4
          I used #include <QtNetwork/QNetworkAccessManager> in controller.cpp and resolved the issue, but I didn't need to add the path QtNetwork/ in firmwareupgradeview.cpp. why that is?

          J 1 Reply Last reply 7 Nov 2024, 09:06
          0
          • I IPlayGenji6
            7 Nov 2024, 07:14

            @Pl45m4
            I used #include <QtNetwork/QNetworkAccessManager> in controller.cpp and resolved the issue, but I didn't need to add the path QtNetwork/ in firmwareupgradeview.cpp. why that is?

            J Offline
            J Offline
            JonB
            wrote on 7 Nov 2024, 09:06 last edited by JonB 11 Jul 2024, 09:07
            #5

            @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.

            1 Reply Last reply
            0
            • I IPlayGenji6 has marked this topic as solved on 8 Nov 2024, 02:05

            5/5

            7 Nov 2024, 09:06

            • Login

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