Hi,
I've been using QT for about 2 months. Now I have a question.
I dont get notified with the readyread signal when a udp packet has arrived:
//----------mainwindow.cpp---------------
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
udpSocket = new QUdpSocket(0) ;
QHostAddress myAddr = QHostAddress("170.126.62.114") ;
bool result = udpSocket->bind(myAddr, 64009);
result = connect(udpSocket, SIGNAL(readyRead()),
this, SLOT(processPendingDatagrams()));
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow:rocessPendingDatagrams()
{
QByteArray datagram;
do {
datagram.resize(udpSocket->pendingDatagramSize());
udpSocket->readDatagram(datagram.data(), datagram.size());
} while (udpSocket->hasPendingDatagrams());
}
//----------main.cpp---------------
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
//----------mainwindow.h---------------
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QUdpSocket>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow {
Q_OBJECT
public:
MainWindow(QWidget *parent = 0);
~MainWindow();
protected:
void changeEvent(QEvent *e);
private:
Ui::MainWindow *ui;
QUdpSocket *udpSocket;
private slots:
void processPendingDatagrams();
};
#endif // MAINWINDOW_H
Can someone please tell me what i'm doing wrong?
Bookmarks