QT Toolkit

The problem I'm having at the moment is this.
I have a thread running in my application which I want to emit a QT 'signal' when a function in the thread calls a callback function.

I'm running pcap_loop() (from the pcap library) and I've declared the callback function it uses as a static member method of the Qthread it is running in.
This works so far. However I cannot get the callback function to emit the QT signal.

It doesnt seem to see itself as part of the Qthread object, and so when I call the line: "emit Rpacket();"
it errors with: "cannot call member function 'void pcapthread::Rpacket()' without object."
Any help is greatly appreciated :)
my code looks like this.
main.cpp
1
2
3
4
5
6
7
8
int main()
{
  //misc code setup application object w 

  pcapthread sniffeth;
  snifeth.start();
  return w.exec(); //main event loop
}

pcapthread.h
1
2
3
4
5
6
7
8
9
10
11
class pcapthread : public Thread
{
     Q_OBJECT
     protected:
          void run();
     private:
          static void got_packet();
     signals:
          void Rpacket();
}
     


pcapthread.cpp
1
2
3
4
5
6
7
8
9
10
11
12
void pcapthread::run()
{
     //... setup code here 
     pcap_loop(handle, -1, this->got_packet,(u_char*)buff);
}

void pcapthread::got_packet()
{

  emit Rpacket();

}

the method got_packet can not be as static because it calls non static members. So try to delete key word static
I managed to temporarily solve the problem by creating the instance of pcapthread globally.
Topic archived. No new replies allowed.