MainWindow
::MainWindow(QWidget *parent
){
listModel->setStringList(listModelStrList);
listView->setModel(listModel);
setCentralWidget(listView);
listView->setAlternatingRowColors(TRUE);
//udpSocket->bind(514, QUdpSocket::ShareAddress))
if(false == udpSocket->bind(514))//udpSocket->bind(QHostAddress::Any/*QHostAddress::LocalHost*/, 514))
{
tr("bind() error"),
}
else
{
tr("bind() SUCCESS"),
}
connect(udpSocket, SIGNAL(readyRead()),
this, SLOT(readPendingDgrams()));
}
MainWindow::~MainWindow()
{
}
void MainWindow::readPendingDgrams()
{
tr("HAVE DATA !!!"),
while(udpSocket->hasPendingDatagrams())
{
datagram.resize(udpSocket->pendingDatagramSize());
quint16 senderPort;
udpSocket->readDatagram(datagram.data(), datagram.size(),
&sender, &senderPort);
processDatagram(datagram);
}
}
void MainWindow::processDatagram(const QByteArray& dgram)
{
listModelStrList << dgram.data();
}
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();
}
To copy to clipboard, switch view to plain text mode
Bookmarks