Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. Error including Qt5 Network in CMakeLists.txt?
Forum Updated to NodeBB v4.3 + New Features

Error including Qt5 Network in CMakeLists.txt?

Scheduled Pinned Locked Moved C++ Gurus
6 Posts 4 Posters 13.0k Views 3 Watching
  • 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.
  • M Offline
    M Offline
    marmoc
    wrote on 13 Dec 2016, 20:54 last edited by
    #1

    I have very little experience with cmake, and I am struggling with including the modules I need to get the project building. In my .pro file I have the following inclusions:

    QT += core gui widgets printsupport network
    

    When I 'make' the result of running cmake, I get the following error.

    fatal error: QHostAddress: No such file or directory
    

    Here is my CMakeLists.txt file with some defining information removed. I am certain the error is occurring because I have not correctly included Qt Network, but I'm not sure exactly what I'm missing?

    cmake_minimum_required(VERSION 2.8.12)
    project(MyProject)
    add_definitions(-std=c++11)
    
    find_package(Qt5Widgets REQUIRED)
    find_package(Qt5PrintSupport REQUIRED)
    find_package(Qt5Network REQUIRED)
    
    include_directories(${Qt5Widgets_INCLUDE_DIRS})
    add_definitions(${Qt5Widgets_DEFINITIONS})
    
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Qt5Widgets_EXECUTABLE_COMPILE_FLAGS}")
    
    SET(CMAKE_INCLUDE_CURRENT_DIR ON)
    
    SET(MAIN main.cpp)
    SET(MYPROJECTSOURCE ...cpp)
    SET(MYPROJECTHEADERS ....h)
    
    SET(MYPROJECTUI ...ui)
    
    qt5_wrap_cpp(HEADERSMOC ${MYPROJECTHEADERS})
    qt5_wrap_ui (UIMOC  ${MYPROJECTUI})
    
    include_directories(${PROJECT_SOURCE_DIR})
    include_directories(${PROJECT_BINARY_DIR})
    
    add_library(MYPROJECTLIB SHARED
        ${MYPROJECTSOURCE}
        ${HEADERSMOC}
        ${UIMOC}
    )
    
    target_link_libraries(MYPROJECTLIB Qt5::Widgets)
    
    add_executable(MyProject ${MAIN})
    target_link_libraries(MyProject MYPROJECTLIB)
    target_link_libraries(MyProject Qt5::PrintSupport)
    target_link_libraries(MyProject Qt5::Network)
    
    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 13 Dec 2016, 21:19 last edited by
      #2

      Hi and welcome to devnet,

      Did you add the network module after having already configured your project ?

      Which version of cmake are you using ?

      By the way, you shouldn't need most these old Qt specific stuff you have currently. See the CMake manuel in Qt's documentation.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      M 1 Reply Last reply 14 Dec 2016, 11:17
      0
      • S Offline
        S Offline
        stackprogramer
        wrote on 13 Dec 2016, 21:23 last edited by stackprogramer
        #3

        Hi, for making Qt project you have two option:
        1-one using qmake that it can find usually Qt parts library.
        2-cmake ,cmake can not find your files.cmake for your project:
        your post can be better with describing completely errors not part of it .
        for example for using from QtCore, cmake should find QtCoreConfig.cmake

        cmake will be need it.........
        so you shoud set CMAKE_PREFIX_PATH to cmake files directory......!
        in linux you should type :

        export CMAKE_PREFIX_PATH="QTPTH/..../lib/cmake"
        

        cmake error in Qt

        1 Reply Last reply
        0
        • K Offline
          K Offline
          Konstantin Tokarev
          wrote on 14 Dec 2016, 07:54 last edited by
          #4

          You've added only Qt5Widgets to your target, so it cannot use Qt5Network

          1 Reply Last reply
          0
          • S SGaist
            13 Dec 2016, 21:19

            Hi and welcome to devnet,

            Did you add the network module after having already configured your project ?

            Which version of cmake are you using ?

            By the way, you shouldn't need most these old Qt specific stuff you have currently. See the CMake manuel in Qt's documentation.

            M Offline
            M Offline
            marmoc
            wrote on 14 Dec 2016, 11:17 last edited by
            #5

            @SGaist said in Error including Qt5 Network in CMakeLists.txt?:

            Did you add the network module after having already configured your project ?

            I'm not sure I understand this? Can you elaborate?

            Which version of cmake are you using ?

            cmake version is 3.5.1

            Thanks!

            1 Reply Last reply
            0
            • S Offline
              S Offline
              SGaist
              Lifetime Qt Champion
              wrote on 14 Dec 2016, 21:21 last edited by
              #6

              @Konstantin-Tokarev has a point, if you are using QHostAddress in your library target, you forgot to link against Qt5::network

              I was meaning that if you configured your project once and after that you added the dependency to the network module, you would likely need to do a full reconfigure of your project.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0

              1/6

              13 Dec 2016, 20:54

              • Login

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