⚠️ Forum Maintenance: Feb 6th, 8am - 14pm (UTC+2)

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.

    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?


  • Lifetime Qt Champion

    @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