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. How to use/include the QtNetwork Module

How to use/include the QtNetwork Module

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 3 Posters 2.2k 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.
  • J Offline
    J Offline
    JohnSRV
    wrote on last edited by
    #1

    Hello Everyone,

    i'm trying to develop a simple application in C++ that sends Files between two computers over LAN. After some research i found out that the QtNetwork Module is the way to go. I do include the QTcpServer and QTcpSocket in my solution.

    #include <QTcpServer>
    #include <QTcpSocket>

    I added the following path to the Additional Include Directories of my project.

    C:\Qt\5.14.2\msvc2017_64\include\QtNetwork
    I then tried a very simple Code.

    QTcpSocket* pTcpSocket = new QTcpSocket();

    I get the "unresolved external symbol" Error which means that the functions are declared but are not defined. It seems to be a problem with the linking or building of the QtNetwork Module. On the Qt Website i found out that one should add the following line

    QT += network
    Since I have no experience with cmake or qmake i'm not sure where to add this line

    Can anyone please recommend a simple example or explain how to correctly use the Module?

    Thanks!!

    jsulmJ 1 Reply Last reply
    0
    • J JohnSRV

      Hello Everyone,

      i'm trying to develop a simple application in C++ that sends Files between two computers over LAN. After some research i found out that the QtNetwork Module is the way to go. I do include the QTcpServer and QTcpSocket in my solution.

      #include <QTcpServer>
      #include <QTcpSocket>

      I added the following path to the Additional Include Directories of my project.

      C:\Qt\5.14.2\msvc2017_64\include\QtNetwork
      I then tried a very simple Code.

      QTcpSocket* pTcpSocket = new QTcpSocket();

      I get the "unresolved external symbol" Error which means that the functions are declared but are not defined. It seems to be a problem with the linking or building of the QtNetwork Module. On the Qt Website i found out that one should add the following line

      QT += network
      Since I have no experience with cmake or qmake i'm not sure where to add this line

      Can anyone please recommend a simple example or explain how to correctly use the Module?

      Thanks!!

      jsulmJ Online
      jsulmJ Online
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @JohnSRV said in How to use/include the QtNetwork Module:

      i'm not sure where to add this line

      Open your pro file and add that line there other "QT += " lines are.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      2
      • VRoninV Offline
        VRoninV Offline
        VRonin
        wrote on last edited by
        #3

        if you are using a CMake project add
        find_package(Qt5 COMPONENTS Network REQUIRED) and then target_link_libraries(MyApp PUBLIC Qt5::Network) where MyApp is the name of your target

        "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
        ~Napoleon Bonaparte

        On a crusade to banish setIndexWidget() from the holy land of Qt

        1 Reply Last reply
        2
        • J Offline
          J Offline
          JohnSRV
          wrote on last edited by
          #4

          Hey,
          thanks for the answers. I'm actually using a Visual Studio 2017 Project and that's why I'm confused. There's no pro File under the Path of my Project :/.
          Is it at all possible to use the Qt Network Module in a visual Studio 2017 Project ??

          Thanks !

          1 Reply Last reply
          0
          • VRoninV Offline
            VRoninV Offline
            VRonin
            wrote on last edited by
            #5

            If you have the Qt Visual Studio Tools installed then right click on your project, go into the Qt Project property and in the modules tab put a tick next to Network

            "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
            ~Napoleon Bonaparte

            On a crusade to banish setIndexWidget() from the holy land of Qt

            1 Reply Last reply
            1
            • J Offline
              J Offline
              JohnSRV
              wrote on last edited by
              #6

              no I don't have the Qt VS Tools installed. How can i install them? Thanks !!

              1 Reply Last reply
              0
              • J Offline
                J Offline
                JohnSRV
                wrote on last edited by
                #7

                Update

                Now I installed the QT Vs Tools for VS 2017. Do I have to start new Project to add the Network Module or can i add it to my already exisiting VS Project?

                1 Reply Last reply
                0
                • VRoninV Offline
                  VRoninV Offline
                  VRonin
                  wrote on last edited by
                  #8

                  Last time I used the VS Tools (that was with VS 2013) it required to start a project from scratch, not sure if they introduced a "convert to qt project" feature since

                  "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                  ~Napoleon Bonaparte

                  On a crusade to banish setIndexWidget() from the holy land of Qt

                  1 Reply Last reply
                  0

                  • Login

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