我添加了一個類IcecastServer到我的QT項目中,將頭文件添加到pro文件並添加了一些代碼。每次我編譯出現以下錯誤:QT未定義的參考錯誤,當試圖編譯
發佈/ icecastserver.o:icecastserver.cpp :(文字+ 0x39):未定義參考
_imp___ZN10QTcpServerC1EP7QObject' release/icecastserver.o:icecastserver.cpp:(.text+0x50): undefined reference to
小鬼ZN12QHostAddressC1ENS_14SpecialAddressE」 發佈/ icecastserver.o:icecastserver 。的.cpp :(文本+ 0x68)中:未定義參照_imp___ZN10QTcpServer6listenERK12QHostAddresst' release/icecastserver.o:icecastserver.cpp:(.text+0x73): undefined reference to
_imp _ZN12QHostAddressD1Ev ' 釋放/ icecastserver.o:icecastserver.cpp :(文本+ 0x9d):未定義參照_imp___ZNK10QTcpServer11errorStringEv' release/icecastserver.o:icecastserver.cpp:(.text+0x3d4): undefined reference to
小鬼ZN12QHostAddressD1Ev' 釋放/ icecastserver的.o:icecastse 。rver.cpp :(文本+ 0x4bd):未定義參照_imp___ZN10QTcpServerC1EP7QObject' release/icecastserver.o:icecastserver.cpp:(.text+0x4d4): undefined reference to
_imp _ZN12QHostAddressC1ENS_14SpecialAddressE ' 釋放/ icecastserver.o:icecastserver.cpp :(文本+ 0x4ec):未定義參照_imp___ZN10QTcpServer6listenERK12QHostAddresst' release/icecastserver.o:icecastserver.cpp:(.text+0x4f7): undefined reference to
小鬼ZN12QHostAddressD1Ev' 釋放/ icecastserver.o:icecastserver.cpp :(文字+ 0x521):未定義參考_imp___ZNK10QTcpServer11errorStringEv' release/icecastserver.o:icecastserver.cpp:(.text+0x858): undefined reference to
_imp _ZN12QHostAddressD1Ev」
我在做什麼錯?
這是頭文件:
#ifndef ICECASTSERVER_H
#define ICECASTSERVER_H
#include <QObject>
QT_BEGIN_NAMESPACE
class QTcpServer;
QT_END_NAMESPACE
class IcecastServer : public QObject
{
Q_OBJECT
public:
explicit IcecastServer(QObject *parent = 0);
signals:
public slots:
private:
QTcpServer *tcpServer;
};
#endif // ICECASTSERVER_H
這是源文件:
#include "icecastserver.h"
#include "QDebug"
#include <QtNetwork/QTcpServer>
#include <QtGui>
IcecastServer::IcecastServer(QObject *parent) :
QObject(parent)
{
tcpServer = new QTcpServer(this);
//tcpServer->listen(QHostAddress::Any,8000);
if (!tcpServer->listen()){
QMessageBox::critical(NULL, tr("Fortune Server"), tr("Unable to start the server: %1.").arg(tcpServer->errorString()));
return;
}
}
我補充說,包括但如你所說,它的評論,所以沒有解決問題。 你在說什麼? – Hedge 2011-04-13 23:33:45
耶!將網絡添加到專業文件解決了問題。對於'QT + = network', – Hedge 2011-04-13 23:43:30
可以在https://doc.qt.io/qt-4.8/qmake-variable-reference.html#qt找到該參考文獻 – n611x007 2017-03-22 09:40:56