Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 363
Mehdi Nouisser Avatar asked Sep 12 '26 08:09

Mehdi Nouisser


1 Answers

The line QT += network must be included in the pro file.. or just append it if you already have other modules..

example

##################################################
#     MY_APP_GUI                           #
##################################################
QT       += core gui network concurrent
CONFIG   += c++14
..

after that just run qmake again and you are ready to go! :)

like image 169
ΦXocę 웃 Пepeúpa ツ Avatar answered Sep 14 '26 21:09

ΦXocę 웃 Пepeúpa ツ