Results 1 to 3 of 3

Thread: Thread,GUI Freeze

  1. #1
    Join Date
    Nov 2008
    Posts
    23
    Thanks
    2

    Default Thread,GUI Freeze

    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:

    Qt Code:
    1. void PcapThread::startCaptureOnInterface()
    2. {
    3. int r;
    4.  
    5. while(captureOn){
    6. struct pcap_pkthdr *header;
    7. const u_char *pkt_data;
    8.  
    9. r = pcap_next_ex(descr,&header,&pkt_data);
    10.  
    11. emit addToWidget(header,pkt_data);
    12.  
    13. }
    To copy to clipboard, switch view to plain text mode 

    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:

    Qt Code:
    1. void MainWindow::startThread()
    2. {
    3. thread1 = new PcapThread();
    4.  
    5. thread1->setDevice(name);
    6. thread1->start();
    7.  
    8. connect(thread1, SIGNAL(addToWidget(struct pcap_pkthdr*,const u_char*)),
    9. packetTable, SLOT(addToWidget(struct pcap_pkthdr*,const u_char*)));
    10.  
    11. }
    To copy to clipboard, switch view to plain text mode 

    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

  2. #2
    Join Date
    Sep 2008
    Location
    New York
    Posts
    90
    Thanks
    13
    Thanked 4 Times in 4 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Thread,GUI Freeze

    Quote Originally Posted by darshan View Post
    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:

    Qt Code:
    1. void PcapThread::startCaptureOnInterface()
    2. {
    3. int r;
    4.  
    5. while(captureOn){
    6. struct pcap_pkthdr *header;
    7. const u_char *pkt_data;
    8.  
    9. r = pcap_next_ex(descr,&header,&pkt_data);
    10.  
    11. emit addToWidget(header,pkt_data);
    12.  
    13. }
    To copy to clipboard, switch view to plain text mode 



    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:

    Qt Code:
    1. void MainWindow::startThread()
    2. {
    3. thread1 = new PcapThread();
    4.  
    5. thread1->setDevice(name);
    6. thread1->start();
    7.  
    8. connect(thread1, SIGNAL(addToWidget(struct pcap_pkthdr*,const u_char*)),
    9. packetTable, SLOT(addToWidget(struct pcap_pkthdr*,const u_char*)));
    10.  
    11. }
    To copy to clipboard, switch view to plain text mode 

    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?

  3. The following user says thank you to Sheng for this useful post:

    darshan (25th February 2009)

  4. #3
    Join Date
    Nov 2008
    Posts
    23
    Thanks
    2

    Default Re: Thread,GUI Freeze

    thanks for that i added a sleep time in milliseconds and thats working fine now.

Similar Threads

  1. Program freeze when timer->stop();
    By gQt in forum Qt Programming
    Replies: 2
    Last Post: 8th January 2009, 14:05
  2. Qt4.2.2: Application freeze
    By arunvv in forum Newbie
    Replies: 1
    Last Post: 9th September 2008, 21:16
  3. SelectAll causes freeze
    By Khal Drogo in forum Qt Programming
    Replies: 20
    Last Post: 4th December 2007, 18:26
  4. Replies: 4
    Last Post: 10th November 2006, 12:07
  5. QTable Freeze Column
    By sunil.thaha in forum Qt Programming
    Replies: 3
    Last Post: 25th April 2006, 04:21

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.