Results 1 to 4 of 4

Thread: emit is slow in Thread?

  1. #1
    Join Date
    Dec 2006
    Posts
    211
    Thanks
    27
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Question emit is slow in Thread?

    Hi All,
    I m using Qt 4.1.5 on my MAC.

    I have a thread from which I m emitting some signal to Gui thread.

    But this emit works fine if I add some small no of Item in treeWidget But if I add suppose 10000 item in treeWidget and emit a signal for each item than the process get very slow infact if thread has completed its work in 20 sec then after 1 and 1/2 min the gui thread complete its work and the process also look like hang in that time period.


    So if somebody knows the issue then plz help me out.

    Thanks.

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: emit is slow in Thread?

    Don't emit 10000 signals. Of course it will be slow, because the GUI event handler will have to handle 10000 events.

    Instead emit fewer signals, but containing more data.
    F.e. emit 100 signals that each add 100 items to the widget. Probably you will have to cache the item data.
    Still, there will be a delay, but the application will be more responsive.

    Regards

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

    vishal.chauhan (2nd August 2007)

  4. #3
    Join Date
    Dec 2006
    Posts
    211
    Thanks
    27
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: emit is slow in Thread?

    OK.

    I will try this.

    I want to ask one more thing that can I take a return value from the emit signal because I want this QTreeWidgetItem pointer to be added in the list which is in thread.

  5. #4
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: emit is slow in Thread?

    Quote Originally Posted by vishal.chauhan View Post
    OK.

    I will try this.

    I want to ask one more thing that can I take a return value from the emit signal because I want this QTreeWidgetItem pointer to be added in the list which is in thread.
    No, you can't have a return value for a signal./ This is mainly because you don't actually implement the signals. You just declare them. The "implementation" is done by moc.

    Qt Code:
    1. because I want this QTreeWidgetItem pointer to be added in the list which is in thread
    To copy to clipboard, switch view to plain text mode 
    Create a small class or struct that has a few members(public, nothing fancy).
    You emit the signal with this an instance of this class as parameter. In the worker thread, before you emit, populate the class with the needed data( the tree item, and whatever you may need in the GUI thread, when you receive the signal ).

    Be careful that when emitting signals with custom types, these types have to be registered with Qt.

    See qRegisterMetaType.

    Regards

  6. The following user says thank you to marcel for this useful post:

    vishal.chauhan (2nd August 2007)

Similar Threads

  1. KDE/QWT doubt on debian sarge
    By hildebrand in forum KDE Forum
    Replies: 13
    Last Post: 25th April 2007, 07:13
  2. Replies: 10
    Last Post: 20th March 2007, 23:19
  3. Problem closing a QMainWindow in Qt4.2
    By ian in forum Qt Programming
    Replies: 11
    Last Post: 17th October 2006, 01:49
  4. How and when to repaint a widget ?
    By yellowmat in forum Newbie
    Replies: 7
    Last Post: 3rd April 2006, 17:36
  5. Replies: 2
    Last Post: 6th January 2006, 22:15

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.