Hello
I am new here. Being looking everywhere to see if I could find an answer to my problem. So here is my problem: I am trying to make a UDP Connection and receive a video stream from a port. I have been referencing to the Qt examples with QUdpSockets and such. The problem is that the program does not seem to be going into the class slot function when I make a connection. I also have to implement this UDP connection using threads because I need to be able to constantly receive the live stream video while doing other stuff in a GUI.

Can anyone please help??

Here is my code:
UdpThread.h
Qt Code:
  1. #ifndef UDPTHREAD
  2. #define UDPTHREAD
  3.  
  4. #include <QtCore>
  5. #include <QHostAddress>
  6. #include <QUdpSocket>
  7. #include <QByteArray>
  8. #include <QPixmap>
  9. #include <QObject>
  10. #include <QBuffer>
  11. #include <QFile>
  12. #include <QThread>
  13.  
  14. class QUdpSocket;
  15.  
  16. class UdpThread : public QObject
  17. {
  18. Q_OBJECT
  19. public:
  20. UdpThread();
  21.  
  22. public slots:
  23. void run();
  24.  
  25. private:
  26. QUdpSocket *udpSocket;
  27. void processTheDatagram(QByteArray);
  28.  
  29. private slots:
  30. void readPackages();
  31.  
  32. };
  33. #endif
To copy to clipboard, switch view to plain text mode 

UdpThread.cpp
Qt Code:
  1. #include <QtGui>
  2. #include <QtNetwork>
  3. #include "UdpThread.h"
  4.  
  5. //Constructor
  6. UdpThread::UdpThread()
  7. {
  8.  
  9. }
  10.  
  11. void UdpThread::run()
  12. {
  13. printf("run test\n");
  14. udpSocket = new QUdpSocket(this);
  15. printf("testing 1 more time\n");
  16.  
  17. udpSocket->bind(QHostAddress::LocalHost, 5555);
  18.  
  19. //SLOT(readPackages()) Does not get executed
  20. connect(udpSocket, SIGNAL(readyRead()), this, SLOT(readPackages()), Qt::DirectConnection);
  21. }
  22.  
  23. //reading data from the port
  24. void UdpThread::readPackages()
  25. {
  26. printf("before test\n"); //Never gets printed or called!
  27. while(udpSocket->hasPendingDatagrams())
  28. {
  29. QByteArray datagram;
  30. datagram.resize(udpSocket->pendingDatagramSize());
  31. udpSocket->readDatagram(datagram.data(), datagram.size()/**, &sender, &senderPort**/);
  32. printf("in while test\n");
  33. processTheDatagram(datagram);
  34. }
  35. }
  36.  
  37. //display the data into an image
  38. void UdpThread::processTheDatagram(QByteArray qba)
  39. {
  40. QPixmap image;
  41. image.loadFromData(qba);
  42. image.save("test", "JPG");
  43. printf("file test\n");
  44. }
To copy to clipboard, switch view to plain text mode 

main.cpp
Qt Code:
  1. #include <QApplication>
  2.  
  3. #include "UdpThread.h"
  4.  
  5. int main(int argc, char **argv)
  6. {
  7. QApplication app(argc, argv);
  8.  
  9. QThread *p = new QThread;
  10. UdpThread *uThread = new UdpThread;
  11. p->start();
  12. uThread->moveToThread(p);
  13. QObject::connect(p, SIGNAL(started()), uThread, SLOT(run()));
  14. return app.exec();
  15. }
To copy to clipboard, switch view to plain text mode 


Thanks for the help.