Results 1 to 3 of 3

Thread: QUdpSocket readyRead() signal not triggered

  1. #1

    Default QUdpSocket readyRead() signal not triggered

    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):

    Qt Code:
    1. MainWindow::MainWindow(QWidget *parent)
    2. : QMainWindow(parent)
    3. {
    4. listView = new QListView(this);
    5. listModel = new QStringListModel();
    6. listModel->setStringList(listModelStrList);
    7. listView->setModel(listModel);
    8. setCentralWidget(listView);
    9. listView->setAlternatingRowColors(TRUE);
    10. udpSocket = new QUdpSocket(this);
    11. //udpSocket->bind(514, QUdpSocket::ShareAddress))
    12. if(false == udpSocket->bind(514))//udpSocket->bind(QHostAddress::Any/*QHostAddress::LocalHost*/, 514))
    13. {
    14. QMessageBox::warning(this, tr("LogViews"),
    15. tr("bind() error"),
    16. }
    17. else
    18. {
    19. QMessageBox::warning(this, tr("LogViews"),
    20. tr("bind() SUCCESS"),
    21. }
    22. connect(udpSocket, SIGNAL(readyRead()),
    23. this, SLOT(readPendingDgrams()));
    24. }
    25.  
    26. MainWindow::~MainWindow()
    27. {
    28.  
    29. }
    30.  
    31. void MainWindow::readPendingDgrams()
    32. {
    33. QMessageBox::warning(this, tr("LogViews"),
    34. tr("HAVE DATA !!!"),
    35. while(udpSocket->hasPendingDatagrams())
    36. {
    37. QByteArray datagram;
    38. datagram.resize(udpSocket->pendingDatagramSize());
    39. QHostAddress sender;
    40. quint16 senderPort;
    41. udpSocket->readDatagram(datagram.data(), datagram.size(),
    42. &sender, &senderPort);
    43. processDatagram(datagram);
    44. }
    45. }
    46.  
    47. void MainWindow::processDatagram(const QByteArray& dgram)
    48. {
    49. listModelStrList << dgram.data();
    50. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QUdpSocket readyRead() signal not triggered

    Post your header file.

  3. #3
    Join Date
    Jul 2010
    Location
    Fortaleza, Brazil
    Posts
    4
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QUdpSocket readyRead() signal not triggered

    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.

Similar Threads

  1. Replies: 1
    Last Post: 11th April 2010, 14:21
  2. QNetworkReply & delayed readyRead(() signal
    By dmini in forum Qt Programming
    Replies: 1
    Last Post: 6th November 2009, 13:47
  3. Replies: 1
    Last Post: 9th July 2009, 08:59
  4. Replies: 1
    Last Post: 29th February 2008, 23:04
  5. readyRead signal too slow or what?
    By Morea in forum Qt Programming
    Replies: 1
    Last Post: 6th July 2007, 19:11

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.