C++ Qt套接字问题

C++ Qt套接字问题,c++,qt,sockets,linker,C++,Qt,Sockets,Linker,我不明白为什么会出现这些错误。我正在使用Qt4.7.4。我正在尝试制作一个使用套接字进行通信的客户机/服务器程序。我在VisualStudio2008中使用winsock2库编写了工作代码。这段代码拒绝使用Qt,我试了几天。我不断收到链接器错误,所以我决定尝试从零开始使用QTcpSocket。我在.pro文件中包含了所有必需的include路径,并且我得到了链接器错误 这是我的客户端类: toplevelcomms.h 这是.pro文件 这是输出: 我在Qt上遇到了很多令人沮丧的问题…我似乎永远

我不明白为什么会出现这些错误。我正在使用Qt4.7.4。我正在尝试制作一个使用套接字进行通信的客户机/服务器程序。我在VisualStudio2008中使用winsock2库编写了工作代码。这段代码拒绝使用Qt,我试了几天。我不断收到链接器错误,所以我决定尝试从零开始使用QTcpSocket。我在.pro文件中包含了所有必需的include路径,并且我得到了链接器错误

这是我的客户端类:

toplevelcomms.h

这是.pro文件

这是输出:

我在Qt上遇到了很多令人沮丧的问题…我似乎永远都不知道如何正确地添加库,而我尝试的每一件新事物都需要花费很长时间才能开始工作…我是否遗漏了一些东西

请回答以下问题:

我当前的代码有什么问题,如何修复? Qt有什么问题吗?为什么我很难使用新的库和类? 在.pro文件中,您需要添加网络模块:

QT       += core gui network

非常感谢你。。。我非常喜欢Qt,但是我缺少一些关于如何正确使用不同库并将它们合并到我的项目中的基本知识。有什么材料可以让我参考,这样我可以更好地自学吗?@PTBG:当我使用Qt时,我发现它既简单又充分。一开始看起来好像很多,但在学习了基础知识之后,你会对深入研究的方向有一个更好的了解。我将开始通读。我真的很感谢你的帮助,再次非常感谢!解决了我的问题!谢谢
#include "toplevelcomms.h"
#include "stdio.h"

TopLevelComms::TopLevelComms(QString hostIP, quint16 hostPort)
{
    tcpSocket = new QTcpSocket();
    hostAddress.setAddress(hostIP);
    this->hostPort = hostPort;

}


void TopLevelComms::connect(){
    //tcpSocket->connectToHost();
}
include( $${PWD}/../qwtbuild.pri )
include( $${PWD}/../qwtconfig.pri )

QT       += core gui

TARGET = TSLSuite
TEMPLATE = app

... // *all my files are declared here*


CONFIG += qwt

INCLUDEPATH += $${PWD}/../include
INCLUDEPATH += C:/QtSDK/Desktop/Qt/4.7.4/msvc2008/include/Qt
INCLUDEPATH += C:/QtSDK/Simulator/Qt/msvc2008/bin
INCLUDEPATH += C:/QtSDK/Simulator/Qt/msvc2008/include/QtNetwork

LIBS += -LC:/Qwt-6.0.1/lib -lqwt
LIBS += -LC:/Qt/4.7.4/lib -lQtSvg
11:33:57: Running build steps for project TSLSuite...
11:33:57: Configuration unchanged, skipping qmake step.
11:33:57: Starting: "C:\QtSDK\QtCreator\bin\jom.exe" 
    C:\QtSDK\QtCreator\bin\jom.exe -nologo -j 2 -f Makefile.Release all
linking release\TSLSuite.exe 
toplevelcomms.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall QHostAddress::~QHostAddress(void)" (__imp_??1QHostAddress@@QAE@XZ) referenced in function __unwindfunclet$??0TopLevelComms@@QAE@VQString@@G@Z$0
toplevelcomms.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: bool __thiscall QHostAddress::setAddress(class QString const &)" (__imp_?setAddress@QHostAddress@@QAE_NABVQString@@@Z) referenced in function "public: __thiscall TopLevelComms::TopLevelComms(class QString,unsigned short)" (??0TopLevelComms@@QAE@VQString@@G@Z)
toplevelcomms.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall QTcpSocket::QTcpSocket(class QObject *)" (__imp_??0QTcpSocket@@QAE@PAVQObject@@@Z) referenced in function "public: __thiscall TopLevelComms::TopLevelComms(class QString,unsigned short)" (??0TopLevelComms@@QAE@VQString@@G@Z)
toplevelcomms.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall QHostAddress::QHostAddress(void)" (__imp_??0QHostAddress@@QAE@XZ) referenced in function "public: __thiscall TopLevelComms::TopLevelComms(class QString,unsigned short)" (??0TopLevelComms@@QAE@VQString@@G@Z)
toplevelcomms.obj : error LNK2001: unresolved external symbol "public: virtual struct QMetaObject const * __thiscall QTcpSocket::metaObject(void)const " (?metaObject@QTcpSocket@@UBEPBUQMetaObject@@XZ)
toplevelcomms.obj : error LNK2001: unresolved external symbol "public: virtual void * __thiscall QTcpSocket::qt_metacast(char const *)" (?qt_metacast@QTcpSocket@@UAEPAXPBD@Z)
toplevelcomms.obj : error LNK2001: unresolved external symbol "public: virtual int __thiscall QTcpSocket::qt_metacall(enum QMetaObject::Call,int,void * *)" (?qt_metacall@QTcpSocket@@UAEHW4Call@QMetaObject@@HPAPAX@Z)
toplevelcomms.obj : error LNK2001: unresolved external symbol "public: virtual bool __thiscall QAbstractSocket::isSequential(void)const " (?isSequential@QAbstractSocket@@UBE_NXZ)
toplevelcomms.obj : error LNK2001: unresolved external symbol "public: virtual void __thiscall QAbstractSocket::close(void)" (?close@QAbstractSocket@@UAEXXZ)
toplevelcomms.obj : error LNK2001: unresolved external symbol "public: virtual bool __thiscall QAbstractSocket::atEnd(void)const " (?atEnd@QAbstractSocket@@UBE_NXZ)
toplevelcomms.obj : error LNK2001: unresolved external symbol "public: virtual __int64 __thiscall QAbstractSocket::bytesAvailable(void)const " (?bytesAvailable@QAbstractSocket@@UBE_JXZ)
toplevelcomms.obj : error LNK2001: unresolved external symbol "public: virtual __int64 __thiscall QAbstractSocket::bytesToWrite(void)const " (?bytesToWrite@QAbstractSocket@@UBE_JXZ)
toplevelcomms.obj : error LNK2001: unresolved external symbol "public: virtual bool __thiscall QAbstractSocket::canReadLine(void)const " (?canReadLine@QAbstractSocket@@UBE_NXZ)
toplevelcomms.obj : error LNK2001: unresolved external symbol "public: virtual bool __thiscall QAbstractSocket::waitForReadyRead(int)" (?waitForReadyRead@QAbstractSocket@@UAE_NH@Z)
toplevelcomms.obj : error LNK2001: unresolved external symbol "public: virtual bool __thiscall QAbstractSocket::waitForBytesWritten(int)" (?waitForBytesWritten@QAbstractSocket@@UAE_NH@Z)
toplevelcomms.obj : error LNK2001: unresolved external symbol "protected: virtual __int64 __thiscall QAbstractSocket::readData(char *,__int64)" (?readData@QAbstractSocket@@MAE_JPAD_J@Z)
toplevelcomms.obj : error LNK2001: unresolved external symbol "protected: virtual __int64 __thiscall QAbstractSocket::readLineData(char *,__int64)" (?readLineData@QAbstractSocket@@MAE_JPAD_J@Z)
toplevelcomms.obj : error LNK2001: unresolved external symbol "protected: virtual __int64 __thiscall QAbstractSocket::writeData(char const *,__int64)" (?writeData@QAbstractSocket@@MAE_JPBD_J@Z)
toplevelcomms.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual __thiscall QTcpSocket::~QTcpSocket(void)" (__imp_??1QTcpSocket@@UAE@XZ) referenced in function "public: virtual void * __thiscall QTcpSocket::`scalar deleting destructor'(unsigned int)" (??_GQTcpSocket@@UAEPAXI@Z)
release\TSLSuite.exe : fatal error LNK1120: 19 unresolved externals

jom 1.0.6 - empower your cores

command failed with exit code 1120
command failed with exit code 2
11:33:58: The process "C:\QtSDK\QtCreator\bin\jom.exe" exited with code 2.
Error while building project TSLSuite (target: Desktop)
When executing build step 'Make'
QT       += core gui network