如何使用/包含 QtNetwork 模块 [英] How to use/include the QtNetwork Module

查看:90
本文介绍了如何使用/包含 QtNetwork 模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试用 C++ 开发一个简单的应用程序,该应用程序通过 LAN 在两台计算机之间发送文件.经过一些研究,我发现 QtNetwork 模块是要走的路.我的解决方案中确实包含了 QTcpServer 和 QTcpSocket.

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();

我收到未解析的外部符号"错误,这意味着函数已声明但未定义.QtNetwork 模块的链接或构建似乎有问题.在 Qt 网站上,我发现应该添加以下行

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

由于我没有使用 cmake 或 qmake 的经验,所以我不确定在哪里添加这一行

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?

推荐答案

更新

因此,如果有人曾经在 Visual Studio 中使用 qt 并且想要将 Qt 网络模块或任何其他 Qt 模块添加到 Vs 项目,您只需将 Qt 库的路径添加到您的其他库目录中.在我的情况下是

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

在C/C++下->一般在这种情况下将Path添加到Module的Header中

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

在链接器下 --> 输入添加用于调试模式的 QtNetworkd.lib 和用于发布的 QtNetwork.lib.

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

最后从C:\Qt\5.14.2\msvc2017_64\bin复制QtNetworkd.dll和QtNetwork.dll,分别添加到你的项目中x64/Debug和x64/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.

这篇关于如何使用/包含 QtNetwork 模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆