PDA

View Full Version : Thread,GUI Freeze



darshan
25th February 2009, 19:43
hello

i have searched the forums already on this topic but can't seem to find a solution to the problem im having.

I have a thread which emits a signal like this:


void PcapThread::startCaptureOnInterface()
{
int r;

while(captureOn){
struct pcap_pkthdr *header;
const u_char *pkt_data;

r = pcap_next_ex(descr,&header,&pkt_data);

emit addToWidget(header,pkt_data);

}

as soon as pcap gets packets it is sent to the slot in the other class object and the table widget is filled with all packet details. This runs in a loop and outputs data into the table using tableWidget->setItem().

The capturing process is really fast when using high bandwidth and this causes the gui to freeze.

In the main gui thread i have implemented the connection like so:


void MainWindow::startThread()
{
thread1 = new PcapThread();

thread1->setDevice(name);
thread1->start();

connect(thread1, SIGNAL(addToWidget(struct pcap_pkthdr*,const u_char*)),
packetTable, SLOT(addToWidget(struct pcap_pkthdr*,const u_char*)));

}

I assume this is a direct connection and not Queued? How do i set it to queued? I tried Qt::QueuedConnection and moveToThread() function here in startThread() but that only helps slightly improve the performance but the gui still freezes.

Any help would be appreciated :)

Sheng
25th February 2009, 19:54
hello

i have searched the forums already on this topic but can't seem to find a solution to the problem im having.

I have a thread which emits a signal like this:


void PcapThread::startCaptureOnInterface()
{
int r;

while(captureOn){
struct pcap_pkthdr *header;
const u_char *pkt_data;

r = pcap_next_ex(descr,&header,&pkt_data);

emit addToWidget(header,pkt_data);

}



as soon as pcap gets packets it is sent to the slot in the other class object and the table widget is filled with all packet details. This runs in a loop and outputs data into the table using tableWidget->setItem().

The capturing process is really fast when using high bandwidth and this causes the gui to freeze.

In the main gui thread i have implemented the connection like so:


void MainWindow::startThread()
{
thread1 = new PcapThread();

thread1->setDevice(name);
thread1->start();

connect(thread1, SIGNAL(addToWidget(struct pcap_pkthdr*,const u_char*)),
packetTable, SLOT(addToWidget(struct pcap_pkthdr*,const u_char*)));

}

I assume this is a direct connection and not Queued? How do i set it to queued? I tried Qt::QueuedConnection and moveToThread() function here in startThread() but that only helps slightly improve the performance but the gui still freezes.

Any help would be appreciated :)

Add some sleep time?
Run connect before start of thread?
why signal and slot are same?

darshan
25th February 2009, 20:17
thanks for that i added a sleep time in milliseconds and thats working fine now. :)