求助!QT网络编程中udpsocket 无法writeDatagram
就是按钮按下,向本地发送一个udp数据包。代买如下:cpp文件#include<QtCore>#include<QtNetwork/QHostAddress>voidEm...
就是按钮按下,向本地发送一个udp数据包。
代买如下:
cpp文件
#include <QtCore>
#include <QtNetwork/QHostAddress>
void Emit_udp::on_Button1_clicked()
{
QByteArray datagram;
QDataStream out(&datagram, QIODevice::WriteOnly);
out.setVersion(QDataStream::Qt_4_3);
out <<"1"<<"button_one";
udpsocket->writeDatagram(datagram,QHostAddress::LocalHost,6688);
ui->label->setText("11111~");
}
。h文件
#include <QWidget>
#include <QtNetwork/QUdpSocket>
namespace Ui {
class Emit_udp;
}
class Emit_udp : public QWidget
{
Q_OBJECT
public:
explicit Emit_udp(QWidget *parent = 0);
~Emit_udp();
private slots:
void on_Button1_clicked();
void on_ExitButton_clicked();
private:
Ui::Emit_udp *ui;
QUdpSocket *udpsocket;
};
结果总是在 udpsocket->writeDatagram(datagram,QHostAddress::LocalHost,6688);处报错;
debug/emit_udp.o:E:\QT_WS\emit_udp-build-desktop-Qt_4_8_1_for_Desktop_-_MinGW__Qt_SDK____/../emit_udp/emit_udp.cpp:25: undefined reference to `_imp___ZN12QHostAddressC1ENS_14SpecialAddressE'
不知道怎么回事啊!!!
是不是QHostAddress文件没包含对啊!
总是报undefined reference的错啊! 展开
代买如下:
cpp文件
#include <QtCore>
#include <QtNetwork/QHostAddress>
void Emit_udp::on_Button1_clicked()
{
QByteArray datagram;
QDataStream out(&datagram, QIODevice::WriteOnly);
out.setVersion(QDataStream::Qt_4_3);
out <<"1"<<"button_one";
udpsocket->writeDatagram(datagram,QHostAddress::LocalHost,6688);
ui->label->setText("11111~");
}
。h文件
#include <QWidget>
#include <QtNetwork/QUdpSocket>
namespace Ui {
class Emit_udp;
}
class Emit_udp : public QWidget
{
Q_OBJECT
public:
explicit Emit_udp(QWidget *parent = 0);
~Emit_udp();
private slots:
void on_Button1_clicked();
void on_ExitButton_clicked();
private:
Ui::Emit_udp *ui;
QUdpSocket *udpsocket;
};
结果总是在 udpsocket->writeDatagram(datagram,QHostAddress::LocalHost,6688);处报错;
debug/emit_udp.o:E:\QT_WS\emit_udp-build-desktop-Qt_4_8_1_for_Desktop_-_MinGW__Qt_SDK____/../emit_udp/emit_udp.cpp:25: undefined reference to `_imp___ZN12QHostAddressC1ENS_14SpecialAddressE'
不知道怎么回事啊!!!
是不是QHostAddress文件没包含对啊!
总是报undefined reference的错啊! 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询