debug/widget.o:D:\Files\QT_Project\tcp_test-build-desktop/../tcp_test/widget.cpp:21: undefined reference to `_imp___ZN12QHostAddressC1ENS_14SpecialAddressE'
debug/widget.o:D:\Files\QT_Project\tcp_test-build-desktop/../tcp_test/widget.cpp:21: undefined reference to `_imp___ZN10QTcpServer6listenERK12QHostAddresst'
debug/widget.o:D:\Files\QT_Project\tcp_test-build-desktop/../tcp_test/widget.cpp:21: undefined reference to `_imp___ZN12QHostAddressD1Ev'
debug/widget.o:D:\Files\QT_Project\tcp_test-build-desktop/../tcp_test/widget.cpp:21: undefined reference to `_imp___ZN12QHostAddressD1Ev'
debug/widget.o:D:\Files\QT_Project\tcp_test-build-desktop/../tcp_test/widget.cpp:25: undefined reference to `_imp___ZN10QTcpServer5closeEv'
collect2: ld returned 1 exit status
mingw32-make[1]: Leaving directory `D:/Files/QT_Project/tcp_test-build-desktop'
mingw32-make: Leaving directory `D:/Files/QT_Project/tcp_test-build-desktop'
mingw32-make[1]: *** [debug\tcp_test.exe] Error 1
mingw32-make: *** [debug] Error 2
The process "E:/QT/mingw/bin/mingw32-make.exe" exited with code %2.
Error while building project tcp_test (target: Desktop)
When executing build step 'Make'
我是初学QT,有很多方面都不太懂,这段时间试做一个使用QTcpServer的一个TCP服务器端的例子。
由于是初学,现在一边研究一边写,所以有些没有写全。
希望大大们能帮我找出问题。我使用的是QT官网上下载的4.6.3。
网上说可能有程序还在运行,或者连接出错以及没有函数体,但我都已经检查过,程序并没有运行了,而且我是在编译时出的错,不是在运行时出错,我试过重新启动QT再编译还是不行,我也在pro文件中加入QtNetWork了,也写了一个简单的函数体,但还是不行
下面是我的代码:
widget.h
————————————————————————————————————————
#ifndef WIDGET_H
#define WIDGET_H
#include <QWidget>
#include <QtNetwork/QTcpServer>
#include <QtNetwork/QTcpSocket>
#include <QtNetwork/QHostAddress>
namespace Ui {
class Widget;
}
class Widget : public QWidget
{
Q_OBJECT
public:
explicit Widget(QWidget *parent = 0);
~Widget();
void MyConnect();
void MyDisconnect();
void MySend(QString text);
public slots:
void acceptConnection();
private:
Ui::Widget *ui;
QTcpServer *tcpServer;
QTcpSocket *tcpSocket;
};
#endif // WIDGET_H
————————————————————————————————————————
widget.cpp
————————————————————————————————————————
#include "widget.h"
#include "ui_widget.h"
Widget::Widget(QWidget *parent) :
QWidget(parent),
ui(new Ui::Widget)
{
ui->setupUi(this);
ui->lineEdit->setText("127.0.0.1");
ui->lineEdit_2->setText("8081");
connect(tcpServer, SIGNAL(newConnection()), this, SLOT(acceptConnection()));
}
Widget::~Widget()
{
delete ui;
}
void Widget::MyConnect()
{
tcpServer->listen(QHostAddress::LocalHost,80);
}
void Widget::MyDisconnect()
{
tcpServer->close();
}
void Widget::MySend(QString text)
{
}
void Widget::acceptConnection()
{
ui->textEdit_3->setText("xxxxxx");
}
————————————————————————————————————————
main.cpp
————————————————————————————————————————
#include <QtGui/QApplication>
#include "widget.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Widget w;
w.show();
return a.exec();
}
————————————————————————————————————————
我把pro也放上来,希望大大能帮我解决这个问题,我郁闷了一天了,都找不出答案
tcp_test.pro
———————————————————————
QT += core gui QtNetwork
TARGET = tcp_test
TEMPLATE = app
SOURCES += main.cpp\
widget.cpp
HEADERS += widget.h
FORMS += widget.ui
pro文件改成这样:
QT += core gui network