Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

How to use/include the QtNetwork Module



  • 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!!


  • Qt Champions 2019

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



  • 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



  • 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 !



  • 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



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



  • 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?



  • 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


Log in to reply