Results 1 to 4 of 4

Thread: how to use prograssbar in a thread

  1. #1
    Join Date
    Sep 2008
    Posts
    23
    Thanks
    1
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Question how to use prograssbar in a thread

    hi, there
    I have a main program and from which dispatch 2 threads. The program within each thread is a loop and I do it in sequential. I need to use 2 prograssbar for each of the 4 thread by counting the steps if the loop. I tried to implement it but failed. (It's fine if not using thread). Can someone give me a hint? Thanks a lot.

    I also have a prograssbar to monitor the threads. Each thread will send out signal to increase the bar when it is finshed. Again, this prograssbar's behavior is weird: when progressbar value changed, the bar did not increase immediately. At the end when all threads are finished, the bar shows 100% in text, but the bar itself is only 1/2 full.
    zl
    Last edited by zl2k; 18th September 2008 at 18:22. Reason: updated contents

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: how to use prograssbar in a thread

    You must not touch GUI in worker threads. Use queued signals to deliver progress to the main thread. For example:

    Qt Code:
    1. class MyThread : public QThread
    2. {
    3. signals:
    4. void valueChanged(int value);
    5. };
    6.  
    7. connect(thread, SIGNAL(valueChanged(int)), progressBar, SLOT(setValue(int)));
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  3. #3
    Join Date
    Sep 2008
    Posts
    23
    Thanks
    1
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: how to use prograssbar in a thread

    Can I create the progressbar within the work thread?
    Or should I creat the progressbar outside of the work thread (in it's parent module) and let the work thread signal the progressbar?

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: how to use prograssbar in a thread

    Quote Originally Posted by zl2k View Post
    Can I create the progressbar within the work thread?
    Or should I creat the progressbar outside of the work thread (in it's parent module) and let the work thread signal the progressbar?
    No, you cannot create widgets within worker threads. Don't make the worker thread aware of any progress bars at all. Just emit signals about the progress. Establish the connection in the GUI thread where you have access to both receiver and sender.
    J-P Nurmi

Similar Threads

  1. QT + OpenGL + Thread => aaaahhhhh !
    By anthibug in forum Qt Programming
    Replies: 7
    Last Post: 26th July 2008, 13:36
  2. Replies: 5
    Last Post: 17th January 2008, 21:49
  3. KDE/QWT doubt on debian sarge
    By hildebrand in forum KDE Forum
    Replies: 13
    Last Post: 25th April 2007, 06:13
  4. Problem closing a QMainWindow in Qt4.2
    By ian in forum Qt Programming
    Replies: 11
    Last Post: 17th October 2006, 00:49
  5. [QT4] QThread and printing a QList<QPixmap>
    By KShots in forum Qt Programming
    Replies: 3
    Last Post: 24th April 2006, 21:44

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.