Note that there are some explanatory texts on larger screens.

plurals
  1. POudp packet is not received in QThread
    text
    copied!<p>I'm trying to receive some packets using a <code>udpReceiver</code> class that I have written using <code>qUdpSocket</code> in a separate <code>QThread</code> : </p> <pre><code>class udpThread : public QThread { private: QObject * parent; public: udpThread(QObject * parent = 0) { this-&gt;parent = parent; } void run() { UdpReceiver * test = new UdpReceiver(parent); } }; class UdpReceiver : public QObject { Q_OBJECT private: QUdpSocket * S; int port; public: UdpReceiver(QObject* parent = 0) : QObject(parent) { port = 9003; initialize(); } UdpReceiver(int p,QObject* parent = 0) : QObject(parent) { port = p; initialize(); } void initialize() { S = new QUdpSocket(); S-&gt;bind(port); S-&gt;connect(S,SIGNAL(readyRead()),this,SLOT(readPendingDiagrams())); qDebug() &lt;&lt; "Waiting for UDP data from port " &lt;&lt; port &lt;&lt; " ... \n"; } public slots: void readPendingDiagrams() { while(S-&gt;waitForReadyRead()) { QByteArray datagram; datagram.resize(S-&gt;pendingDatagramSize()); QHostAddress sender; quint16 senderPort; S-&gt;readDatagram(datagram.data(), datagram.size(),&amp;sender, &amp;senderPort); qDebug() &lt;&lt; datagram.size() &lt;&lt; " bytes received .... \n"; qDebug() &lt;&lt; " bytes received .... \n"; } } }; </code></pre> <p>And here is the <code>main()</code> method :</p> <pre><code>int main(int argc, char *argv[]) { QApplication a(argc, argv); // UdpReceiver * net = new UdpReceiver(); MainWindow w; udpThread * ut = new udpThread(); ut-&gt;start(); w.show(); return a.exec(); } </code></pre> <p>Now when I use the <code>udpReceiver</code> class to get the packets without the <code>QThread</code> it works just fine, but when I use the <code>udpThread</code> class it doesn't get the packets or at least the <code>raedyread()</code> signal does not activate some how. When I try to get the packets without the <code>QThread</code> my GUI crashes somehow and the whole program hangs, that's why I want to use <code>QThread</code>. I appreciate if you could help me solve this :) Regards,</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload