PDA

View Full Version : QUdpSocket readyRead() signal not triggered



deionut
4th May 2010, 09:32
Hi

I'm trying to use QUdpSocket on my Windows XP machine to receive datagrams for port number 514 (syslog). The problem is that the readyRead() signal is NEVER triggered; I have run every other udp samples (from QT SDK and books) and they all work. The only difference is that I'm trying to bind the socket to port 514 which is in the range of well-known port numbers (0-1023), maybe I need special rights to bind to this port number. The bind() call succeeds but readPendingDgrams() is never called. I have written a small Win32 C program using WinSock and I am able to receive the syslog datagrams, so it's not like I don't actually receive data. Below is the source code (Oh, I'm newbie to QT):



MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
listView = new QListView(this);
listModel = new QStringListModel();
listModel->setStringList(listModelStrList);
listView->setModel(listModel);
setCentralWidget(listView);
listView->setAlternatingRowColors(TRUE);
udpSocket = new QUdpSocket(this);
//udpSocket->bind(514, QUdpSocket::ShareAddress))
if(false == udpSocket->bind(514))//udpSocket->bind(QHostAddress::Any/*QHostAddress::LocalHost*/, 514))
{
QMessageBox::warning(this, tr("LogViews"),
tr("bind() error"),
QMessageBox::Ok);
}
else
{
QMessageBox::warning(this, tr("LogViews"),
tr("bind() SUCCESS"),
QMessageBox::Ok);
}
connect(udpSocket, SIGNAL(readyRead()),
this, SLOT(readPendingDgrams()));
}

MainWindow::~MainWindow()
{

}

void MainWindow::readPendingDgrams()
{
QMessageBox::warning(this, tr("LogViews"),
tr("HAVE DATA !!!"),
QMessageBox::Ok);
while(udpSocket->hasPendingDatagrams())
{
QByteArray datagram;
datagram.resize(udpSocket->pendingDatagramSize());
QHostAddress sender;
quint16 senderPort;
udpSocket->readDatagram(datagram.data(), datagram.size(),
&sender, &senderPort);
processDatagram(datagram);
}
}

void MainWindow::processDatagram(const QByteArray& dgram)
{
listModelStrList << dgram.data();
}

squidge
4th May 2010, 13:29
Post your header file.

israelins
26th October 2010, 18:19
Did you solve your problem? I'm having the same problem! But in my case they works before but now not work I have seen in my change log, but didn't find anything! I debug and I see the socket notification queue (winSock event) isn't emitted when a package arrives, then the class socket isn't notified, too... I see that in Windows XP, on my Fedora and WinCE the same application works.