How to use/include the QtNetwork Module

▼魔方 西西 提交于 2021-01-27 14:53:05

问题


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?


回答1:


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! :)




回答2:


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.



来源:https://stackoverflow.com/questions/62299816/how-to-use-include-the-qtnetwork-module

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!