c++qtnetwork-programmingqtnetwork

How to use/include the QtNetwork Module


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?


Solution

  • Update

    So if someone is ever using qt in visual studio and wants to add the Qt Network Module or any other Qt Module to the Vs Project you just have to add the Path to the Qt lib to your additional Library Directories. In my Case it was

    C:\Qt\5.14.2\msvc2017_64\lib
    

    Under C/C++-> General add the Path to the Header of the Module in this case

    C:\Qt\5.14.2\msvc2017_64\include\QtNetwork
    

    Under Linker -->Input add QtNetworkd.lib for Debug Mode and QtNetwork.lib for Release.

    At Last copy the QtNetworkd.dll and the QtNetwork.dll from C:\Qt\5.14.2\msvc2017_64\bin and add them to your Project under x64/Debug and x64/release respectively.