Hi,

My (sniffer) appliation has a capture QThread which is awaiting packets from a network interface and shall emit then this received packet to the main (GUI) thread for edicated treatment.
My problem is that emit is called but signal is never received by the client class which which was connected to this signal the main thread.

1 - Any idea why this does not work ?
2 - Can the client class connect to the QThread BEFORE the tread has been started (before call to start()) ?

Thanks.

Note:
The sniffer thread uses pcap library for low level sniffing.

Here below is the simplified code to give an idea of the implementation :

Qt Code:
  1. class SnifferThread : public QThread
  2. {
  3. Q_OBJECT;
  4.  
  5. signals:
  6. void signalPacketReceived(uint8* pData, uint32 pDataLength, uint32 pOrd);
  7. //...
  8. };
  9.  
  10. void SnifferThread::run()
  11. {
  12. pcapfp_ = pcap_open_live(itf.c_str(), PCAP_MAX_NB_BYTE, 1, -1, errorBuffer);
  13. pcap_pkthdr pktHeader;
  14.  
  15. while (canSniff_)
  16. {
  17. isSniffing_ = true;
  18.  
  19. const uint8* data = pcap_next(pcapfp_, &pktHeader);
  20. if ( data != 0 )
  21. {
  22. // ...
  23. emit signalPacketReceived(buffer, bufSize, ++frameNumber_);
  24. }
  25. else
  26. {
  27. // No packet available: very short asleep
  28. QThread::msleep(20);
  29. }
  30. }
  31. }
To copy to clipboard, switch view to plain text mode