【发布时间】:2012-03-29 11:46:50
【问题描述】:
我正在尝试编写一个在 linux 中读取广播的 UDP 数据报的程序。我是套接字编程的初学者。
我的代码是:
#include <QUdpSocket>
#include <iostream>
int main ()
{
QUdpSocket *udpSocket ;
udpSocket= new QUdpSocket(0);
udpSocket->bind(QHostAddress::LocalHost, 3838);
udpSocket->connect(udpSocket, SIGNAL(readyRead()),
this, SLOT(readPendingDatagrams()));
while (1)
{
if (udpSocket->hasPendingDatagrams())
{
QByteArray datagram;
datagram.resize(udpSocket->pendingDatagramSize());
QHostAddress sender;
quint16 senderPort;
udpSocket->readDatagram(datagram.data(), datagram.size(),
&sender, &senderPort);
}
}
}
但它在this 中返回错误。
main.cpp:13:18: 错误:在非成员函数中无效使用“this”
我该怎么办?
【问题讨论】:
标签: qt network-programming udp