#2
bulubulukaka2013-01-21 17:34
|
问题描述:
无法初始化udpsocket。错误提示:
collect2: ld returned 1 exit status
未找到文件
我在网上搜了下,目前有两种说法:
一是之前运行了Qt的程序没有正常关闭,再运行就会提示这个错误——这个已经排除,我重启Qt ctreator后依然会报这个错误。
二是说我有头文件没有添加。
我include的头文件如下:
chat.cpp中:
#include "chat.h"
chat.h中:
程序代码:
#include "main.h"
#include <QGridLayout>
#include <QtNetwork/QUdpSocket>
#include <QtNetwork/QHostAddress>
main.h中:
程序代码:
#include <QWidget>
#include <QLineEdit>
#include <QTextEdit>
#include <QLabel>
#include <QPushButton>
#include <QTextCodec>
#include <QString>
#include <QMessageBox>
#include <QCloseEvent>
#include <QDebug>
#include <QTime>
顺便求教我在构造函数中调用成员方法来初始化socket这样好吗?
程序代码:
//Chat类的构造函数
Chat::Chat(QWidget *parent)
: QWidget(parent)
{
qDebug() << "enter Chat constructor!";
chatLayout = new QGridLayout;
strMsg = codec->toUnicode("对方");
QLabel *clientID = new QLabel(strMsg);
strMsg = codec->toUnicode("我");
QLabel *myID = new QLabel(strMsg);
remoteMsg = new QTextEdit;
localMsg = new QTextEdit;
strBtn = codec->toUnicode("发送");
sendBtn = new QPushButton(strBtn);
//关联按钮、信号和槽;
connect(sendBtn, SIGNAL(clicked()), this, SLOT(on_sendMsg()));
//设置布局
chatLayout->addWidget(clientID,0,0);
chatLayout->addWidget(remoteMsg,1,0);
chatLayout->addWidget(myID,2,0);
chatLayout->addWidget(localMsg,3,0);
chatLayout->addWidget(sendBtn,3,1);
strTitle = codec->toUnicode("聊天中");
setWindowTitle(strTitle);
setLayout(chatLayout);
initSocket();
}
void Chat::initSocket()
{
//设置网络连接
udpSocket1 = new QUdpSocket(this);
ip1 = new QHostAddress(strIP1);
connect(udpSocket1, SIGNAL(readyRead()), this, SLOT(on_receiveMsg()));
}