今天从http://blog.csdn.net/yiyaaixuexi/article/details/6655493上下载了一份关于Qt写的QQ界面源码,我把它转成VS2008的Qt工程,在编译时遇到了一些问题。
1. 无法打开包括文件:“QUdpSocket”:No such file or directory
可能是因为Qt版本(本人用的是Qt4.7.3)的原因,网络模块的TCP、UDP头文件发生了变化。
解决方法:把原先的#include <QUdpSocket>包含加上QtNetwork/,即变成#include <QtNetwork/QUdpSocket>,QTcpSocket、QHostAddress的同理。
(后记):其实此问题并不是路径问题,只要在Qt工程中把QtNetwork library加上去就可以了,而无需把原先的#include <QUdpSocket>包含加上QtNetwork/。
2. QtNetwork库未添加引起的链接问题
链接时出现错误如下:
1>正在生成代码...
1>正在链接...
1>LINK : 没有找到 E:\QtProj\2donkey\Debug\donkeyhead-client.exe 或上一个增量链接没有生成它;正在执行完全链接
1>regdialog.obj : error LNK2019: 无法解析的外部符号 "__declspec(dllimport) public: __thiscall QTcpSocket::QTcpSocket(class QObject *)" (__imp_??0QTcpSocket@@QAE@PAVQObject@@@Z),该符号在函数 "public: __thiscall regdialog::regdialog(class QString,class QString,class QWidget *)" (??0regdialog@@QAE@VQString@@0PAVQWidget@@@Z) 中被引用
1>login.obj : error LNK2001: 无法解析的外部符号 "__declspec(dllimport) public: __thiscall QTcpSocket::QTcpSocket(class QObject *)" (__imp_??0QTcpSocket@@QAE@PAVQObject@@@Z)
1>regdialog.obj : error LNK2001: 无法解析的外部符号 "public: virtual struct QMetaObject const * __thiscall QTcpSocket::metaObject(void)const " (?metaObject@QTcpSocket@@UBEPBUQMetaObject@@XZ)
1>login.obj : error LNK2001: 无法解析的外部符号 "public: virtual struct QMetaObject const * __thiscall QTcpSocket::metaObject(void)const " (?metaObject@QTcpSocket@@UBEPBUQMetaObject@@XZ)
1>regdialog.obj : error LNK2001: 无法解析的外部符号 "public: virtual void * __thiscall QTcpSocket::qt_metacast(char const *)" (?qt_metacast@QTcpSocket@@UAEPAXPBD@Z)
1>login.obj : error LNK2001: 无法解析的外部符号 "public: virtual void * __thiscall QTcpSocket::qt_metacast(char const *)" (?qt_metacast@QTcpSocket@@UAEPAXPBD@Z)
1>regdialog.obj : error LNK2001: 无法解析的外部符号 "public: virtual int __thiscall QTcpSocket::qt_metacall(enum QMetaObject::Call,int,void * *)" (?qt_metacall@QTcpSocket@@UAEHW4Call@QMetaObject@@HPAPAX@Z)
1>login.obj : error LNK2001: 无法解析的外部符号 "public: virtual int __thiscall QTcpSocket::qt_metacall(enum QMetaObject::Call,int,void * *)" (?qt_metacall@QTcpSocket@@UAEHW4Call@QMetaObject@@HPAPAX@Z)
1>regdialog.obj : error LNK2001: 无法解析的外部符号 "public: virtual bool __thiscall QAbstractSocket::isSequential(void)const " (?isSequential@QAbstractSocket@@UBE_NXZ)
1>login.obj : error LNK2001: 无法解析的外部符号 "public: virtual bool __thiscall QAbstractSocket::isSequential(void)const " (?isSequential@QAbstractSocket@@UBE_NXZ)
1>panel.obj : error LNK2001: 无法解析的外部符号 "public: virtual bool __thiscall QAbstractSocket::isSequential(void)const " (?isSequential@QAbstractSocket@@UBE_NXZ)
1>regdialog.obj : error LNK2001: 无法解析的外部符号 "public: virtual void __thiscall QAbstractSocket::close(void)" (?close@QAbstractSocket@@UAEXXZ)
1>login.obj : error LNK2001: 无法解析的外部符号 "public: virtual void __thiscall QAbstractSocket::close(void)" (?close@QAbstractSocket@@UAEXXZ)
1>panel.obj : error LNK2001: 无法解析的外部符号 "public: virtual void __thiscall QAbstractSocket::close(void)" (?close@QAbstractSocket@@UAEXXZ)
1>regdialog.obj : error LNK2001: 无法解析的外部符号 "public: virtual bool __thiscall QAbstractSocket::atEnd(void)const " (?atEnd@QAbstractSocket@@UBE_NXZ)
1>login.obj : error LNK2001: 无法解析的外部符号 "public: virtual bool __thiscall QAbstractSocket::atEnd(void)const " (?atEnd@QAbstractSocket@@UBE_NXZ)
1>panel.obj : error LNK2001: 无法解析的外部符号 "public: virtual bool __thiscall QAbstractSocket::atEnd(void)const " (?atEnd@QAbstractSocket@@UBE_NXZ)
1>regdialog.obj : error LNK2001: 无法解析的外部符号 "public: virtual __int64 __thiscall QAbstractSocket::bytesAvailable(void)const " (?bytesAvailable@QAbstractSocket@@UBE_JXZ)
1>login.obj : error LNK2001: 无法解析的外部符号 "public: virtual __int64 __thiscall QAbstractSocket::bytesAvailable(void)const " (?bytesAvailable@QAbstractSocket@@UBE_JXZ)
1>panel.obj : error LNK2001: 无法解析的外部符号 "public: virtual __int64 __thiscall QAbstractSocket::bytesAvailable(void)const " (?bytesAvailable@QAbstractSocket@@UBE_JXZ)
1>regdialog.obj : error LNK2001: 无法解析的外部符号 "public: virtual __int64 __thiscall QAbstractSocket::bytesToWrite(void)const " (?bytesToWrite@QAbstractSocket@@UBE_JXZ)
1>login.obj : error LNK2001: 无法解析的外部符号 "public: virtual __int64 __thiscall QAbstractSocket::bytesToWrite(void)const " (?bytesToWrite@QAbstractSocket@@UBE_JXZ)
1>panel.obj : error LNK2001: 无法解析的外部符号 "public: virtual __int64 __thiscall QAbstractSocket::bytesToWrite(void)const " (?bytesToWrite@QAbstractSocket@@UBE_JXZ)
1>regdialog.obj : error LNK2001: 无法解析的外部符号 "public: virtual bool __thiscall QAbstractSocket::canReadLine(void)const " (?canReadLine@QAbstractSocket@@UBE_NXZ)
1>login.obj : error LNK2001: 无法解析的外部符号 "public: virtual bool __thiscall QAbstractSocket::canReadLine(void)const " (?canReadLine@QAbstractSocket@@UBE_NXZ)
1>panel.obj : error LNK2001: 无法解析的外部符号 "public: virtual bool __thiscall QAbstractSocket::canReadLine(void)const " (?canReadLine@QAbstractSocket@@UBE_NXZ)
1>regdialog.obj : error LNK2001: 无法解析的外部符号 "public: virtual bool __thiscall QAbstractSocket::waitForReadyRead(int)" (?waitForReadyRead@QAbstractSocket@@UAE_NH@Z)
1>login.obj : error LNK2001: 无法解析的外部符号 "public: virtual bool __thiscall QAbstractSocket::waitForReadyRead(int)" (?waitForReadyRead@QAbstractSocket@@UAE_NH@Z)
1>panel.obj : error LNK2001: 无法解析的外部符号 "public: virtual bool __thiscall QAbstractSocket::waitForReadyRead(int)" (?waitForReadyRead@QAbstractSocket@@UAE_NH@Z)
1>regdialog.obj : error LNK2001: 无法解析的外部符号 "public: virtual bool __thiscall QAbstractSocket::waitForBytesWritten(int)" (?waitForBytesWritten@QAbstractSocket@@UAE_NH@Z)
1>login.obj : error LNK2001: 无法解析的外部符号 "public: virtual bool __thiscall QAbstractSocket::waitForBytesWritten(int)" (?waitForBytesWritten@QAbstractSocket@@UAE_NH@Z)
1>panel.obj : error LNK2019: 无法解析的外部符号 "public: virtual bool __thiscall QAbstractSocket::waitForBytesWritten(int)" (?waitForBytesWritten@QAbstractSocket@@UAE_NH@Z),该符号在函数 "public: virtual __thiscall panel::~panel(void)" (??1panel@@UAE@XZ) 中被引用
1>regdialog.obj : error LNK2001: 无法解析的外部符号 "protected: virtual __int64 __thiscall QAbstractSocket::readData(char *,__int64)" (?readData@QAbstractSocket@@MAE_JPAD_J@Z)
1>login.obj : error LNK2001: 无法解析的外部符号 "protected: virtual __int64 __thiscall QAbstractSocket::readData(char *,__int64)" (?readData@QAbstractSocket@@MAE_JPAD_J@Z)
1>panel.obj : error LNK2001: 无法解析的外部符号 "protected: virtual __int64 __thiscall QAbstractSocket::readData(char *,__int64)" (?readData@QAbstractSocket@@MAE_JPAD_J@Z)
1>regdialog.obj : error LNK2001: 无法解析的外部符号 "protected: virtual __int64 __thiscall QAbstractSocket::readLineData(char *,__int64)" (?readLineData@QAbstractSocket@@MAE_JPAD_J@Z)
1>login.obj : error LNK2001: 无法解析的外部符号 "protected: virtual __int64 __thiscall QAbstractSocket::readLineData(char *,__int64)" (?readLineData@QAbstractSocket@@MAE_JPAD_J@Z)
1>panel.obj : error LNK2001: 无法解析的外部符号 "protected: virtual __int64 __thiscall QAbstractSocket::readLineData(char *,__int64)" (?readLineData@QAbstractSocket@@MAE_JPAD_J@Z)
1>regdialog.obj : error LNK2001: 无法解析的外部符号 "protected: virtual __int64 __thiscall QAbstractSocket::writeData(char const *,__int64)" (?writeData@QAbstractSocket@@MAE_JPBD_J@Z)
1>login.obj : error LNK2001: 无法解析的外部符号 "protected: virtual __int64 __thiscall QAbstractSocket::writeData(char const *,__int64)" (?writeData@QAbstractSocket@@MAE_JPBD_J@Z)
1>panel.obj : error LNK2001: 无法解析的外部符号 "protected: virtual __int64 __thiscall QAbstractSocket::writeData(char const *,__int64)" (?writeData@QAbstractSocket@@MAE_JPBD_J@Z)
1>regdialog.obj : error LNK2019: 无法解析的外部符号 "__declspec(dllimport) public: virtual __thiscall QTcpSocket::~QTcpSocket(void)" (__imp_??1QTcpSocket@@UAE@XZ),该符号在函数 "public: virtual void * __thiscall QTcpSocket::`scalar deleting destructor'(unsigned int)" (??_GQTcpSocket@@UAEPAXI@Z) 中被引用
1>login.obj : error LNK2001: 无法解析的外部符号 "__declspec(dllimport) public: virtual __thiscall QTcpSocket::~QTcpSocket(void)" (__imp_??1QTcpSocket@@UAE@XZ)
1>regdialog.obj : error LNK2019: 无法解析的外部符号 "__declspec(dllimport) public: __thiscall QHostAddress::~QHostAddress(void)" (__imp_??1QHostAddress@@QAE@XZ),该符号在函数 "private: void __thiscall regdialog::on_submitButton_clicked(void)" (?on_submitButton_clicked@regdialog@@AAEXXZ) 中被引用
1>chatform.obj : error LNK2001: 无法解析的外部符号 "__declspec(dllimport) public: __thiscall QHostAddress::~QHostAddress(void)" (__imp_??1QHostAddress@@QAE@XZ)
1>login.obj : error LNK2001: 无法解析的外部符号 "__declspec(dllimport) public: __thiscall QHostAddress::~QHostAddress(void)" (__imp_??1QHostAddress@@QAE@XZ)
1>panel.obj : error LNK2001: 无法解析的外部符号 "__declspec(dllimport) public: __thiscall QHostAddress::~QHostAddress(void)" (__imp_??1QHostAddress@@QAE@XZ)
1>regdialog.obj : error LNK2019: 无法解析的外部符号 "__declspec(dllimport) public: void __thiscall QAbstractSocket::connectToHost(class QHostAddress const &,unsigned short,class QFlags<enum QIODevice::OpenModeFlag>)" (__imp_?connectToHost@QAbstractSocket@@QAEXABVQHostAddress@@GV?$QFlags@W4OpenModeFlag@QIODevice@@@@@Z),该符号在函数 "private: void __thiscall regdialog::on_submitButton_clicked(void)" (?on_submitButton_clicked@regdialog@@AAEXXZ) 中被引用
1>login.obj : error LNK2001: 无法解析的外部符号 "__declspec(dllimport) public: void __thiscall QAbstractSocket::connectToHost(class QHostAddress const &,unsigned short,class QFlags<enum QIODevice::OpenModeFlag>)" (__imp_?connectToHost@QAbstractSocket@@QAEXABVQHostAddress@@GV?$QFlags@W4OpenModeFlag@QIODevice@@@@@Z)
1>regdialog.obj : error LNK2019: 无法解析的外部符号 "__declspec(dllimport) public: __thiscall QHostAddress::QHostAddress(class QString const &)" (__imp_??0QHostAddress@@QAE@ABVQString@@@Z),该符号在函数 "private: void __thiscall regdialog::on_submitButton_clicked(void)" (?on_submitButton_clicked@regdialog@@AAEXXZ) 中被引用
1>chatform.obj : error LNK2001: 无法解析的外部符号 "__declspec(dllimport) public: __thiscall QHostAddress::QHostAddress(class QString const &)" (__imp_??0QHostAddress@@QAE@ABVQString@@@Z)
1>login.obj : error LNK2001: 无法解析的外部符号 "__declspec(dllimport) public: __thiscall QHostAddress::QHostAddress(class QString const &)" (__imp_??0QHostAddress@@QAE@ABVQString@@@Z)
1>panel.obj : error LNK2001: 无法解析的外部符号 "__declspec(dllimport) public: __thiscall QHostAddress::QHostAddress(class QString const &)" (__imp_??0QHostAddress@@QAE@ABVQString@@@Z)
1>regdialog.obj : error LNK2019: 无法解析的外部符号 "__declspec(dllimport) public: void __thiscall QAbstractSocket::abort(void)" (__imp_?abort@QAbstractSocket@@QAEXXZ),该符号在函数 "private: void __thiscall regdialog::on_submitButton_clicked(void)" (?on_submitButton_clicked@regdialog@@AAEXXZ) 中被引用
1>login.obj : error LNK2001: 无法解析的外部符号 "__declspec(dllimport) public: void __thiscall QAbstractSocket::abort(void)" (__imp_?abort@QAbstractSocket@@QAEXXZ)
1>chatform.obj : error LNK2019: 无法解析的外部符号 "__declspec(dllimport) public: __int64 __thiscall QUdpSocket::writeDatagram(char const *,__int64,class QHostAddress const &,unsigned short)" (__imp_?writeDatagram@QUdpSocket@@QAE_JPBD_JABVQHostAddress@@G@Z),该符号在函数 "private: void __thiscall chatform::on_sendButton_clicked(void)" (?on_sendButton_clicked@chatform@@AAEXXZ) 中被引用
1>panel.obj : error LNK2001: 无法解析的外部符号 "__declspec(dllimport) public: __int64 __thiscall QUdpSocket::writeDatagram(char const *,__int64,class QHostAddress const &,unsigned short)" (__imp_?writeDatagram@QUdpSocket@@QAE_JPBD_JABVQHostAddress@@G@Z)
1>panel.obj : error LNK2019: 无法解析的外部符号 "__declspec(dllimport) public: bool __thiscall QUdpSocket::bind(unsigned short)" (__imp_?bind@QUdpSocket@@QAE_NG@Z),该符号在函数 "public: void __thiscall panel::init(void)" (?init@panel@@QAEXXZ) 中被引用
1>panel.obj : error LNK2019: 无法解析的外部符号 "__declspec(dllimport) public: __thiscall QUdpSocket::QUdpSocket(class QObject *)" (__imp_??0QUdpSocket@@QAE@PAVQObject@@@Z),该符号在函数 "public: void __thiscall panel::init(void)" (?init@panel@@QAEXXZ) 中被引用
1>panel.obj : error LNK2001: 无法解析的外部符号 "public: virtual struct QMetaObject const * __thiscall QUdpSocket::metaObject(void)const " (?metaObject@QUdpSocket@@UBEPBUQMetaObject@@XZ)
1>panel.obj : error LNK2001: 无法解析的外部符号 "public: virtual void * __thiscall QUdpSocket::qt_metacast(char const *)" (?qt_metacast@QUdpSocket@@UAEPAXPBD@Z)
1>panel.obj : error LNK2001: 无法解析的外部符号 "public: virtual int __thiscall QUdpSocket::qt_metacall(enum QMetaObject::Call,int,void * *)" (?qt_metacall@QUdpSocket@@UAEHW4Call@QMetaObject@@HPAPAX@Z)
1>panel.obj : error LNK2019: 无法解析的外部符号 "__declspec(dllimport) public: virtual __thiscall QUdpSocket::~QUdpSocket(void)" (__imp_??1QUdpSocket@@UAE@XZ),该符号在函数 "public: virtual void * __thiscall QUdpSocket::`scalar deleting destructor'(unsigned int)" (??_GQUdpSocket@@UAEPAXI@Z) 中被引用
1>panel.obj : error LNK2019: 无法解析的外部符号 "__declspec(dllimport) public: __int64 __thiscall QUdpSocket::readDatagram(char *,__int64,class QHostAddress *,unsigned short *)" (__imp_?readDatagram@QUdpSocket@@QAE_JPAD_JPAVQHostAddress@@PAG@Z),该符号在函数 "private: void __thiscall panel::recvMsg(void)" (?recvMsg@panel@@AAEXXZ) 中被引用
1>panel.obj : error LNK2019: 无法解析的外部符号 "__declspec(dllimport) public: __int64 __thiscall QUdpSocket::pendingDatagramSize(void)const " (__imp_?pendingDatagramSize@QUdpSocket@@QBE_JXZ),该符号在函数 "private: void __thiscall panel::recvMsg(void)" (?recvMsg@panel@@AAEXXZ) 中被引用
1>panel.obj : error LNK2019: 无法解析的外部符号 "__declspec(dllimport) public: __thiscall QHostAddress::QHostAddress(void)" (__imp_??0QHostAddress@@QAE@XZ),该符号在函数 "private: void __thiscall panel::recvMsg(void)" (?recvMsg@panel@@AAEXXZ) 中被引用
1>E:\QtProj\2donkey\Debug\donkeyhead-client.exe : fatal error LNK1120: 30 个无法解析的外部命令
1>生成日志保存在“file://E:\QtProj\2donkey\Debug\BuildLog.htm”
1>donkeyhead-client - 67 个错误,0 个警告
========== 生成: 成功 0 个,失败 1 个,最新 0 个,跳过 0 个 ==========
这是因为在Qt工程中未添加QtNetwork库的原因。在VS2008的Qt工程中默认只添加了Core library和GUI library两个库。
解决方法:项目属性—>右键—>Qt Project Settings—>Qt Modules界面中,勾选Network library,然后重新编译即可。