Results 1 to 4 of 4

Thread: Progress Bar Dialog using threads

  1. #1
    Join Date
    Apr 2010
    Posts
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Progress Bar Dialog using threads

    HI,
    I am trying to call Progress bar Dialog using thread from my main gui window but the progress bar does not proceed. Here is the code snippet.

    From main
    ************

    Qt Code:
    1. myGUI::myGUI(QWidget *parent, Qt::WFlags flags)
    2. :QMainWindow(parent, flags),
    3. m_UiIsReadyToQuit(false)
    4. {
    5. ui.setupUi(this);
    6. mProgressBarDialog = NULL;
    7. connect(&thread, SIGNAL(ShowPB()),myPBarDialog,SLOT(PBoutput()));
    8. }
    9.  
    10. void myGUI::Add_clicked()
    11. {
    12. if(myProBarDialog == NULL) {
    13. myProBarDialog = new proBarDialog(this);
    14. }
    15. myProBarDialog->show();
    16.  
    17. // call the thread here
    18. thread.render();
    19.  
    20. updateInstanceList();
    21.  
    22. // Stop the thread here
    23. if (mProgressBarDialog != NULL)
    24. {
    25. mProgressBarDialog->close();
    26. mProgressBarDialog = NULL;
    27. }
    28. thread.stop();
    29. }
    To copy to clipboard, switch view to plain text mode 

    Thread code is like this
    *****************
    Qt Code:
    1. void PBarThread::render()
    2. {
    3. start(HighestPriority);
    4. }
    5.  
    6.  
    7. void PBarThread::run()
    8. {
    9. emit ShowPB();
    10. }
    11.  
    12. and PBarDialog code is like this
    13. ******************
    14. pBarDialog::pBarDialog(QWidget *parent)
    15. : QDialog(parent)
    16. {
    17. ui.setupUi(this);
    18. ui.pBar->show();
    19.  
    20. }
    21.  
    22. void pBarDialog::PBoutput()
    23. {
    24. ui.pBar->show();
    25. }
    To copy to clipboard, switch view to plain text mode 

    In Debug mode I can see that the call goes to ui.pBar->show() (not in PBOutput function). I see a frozen progress dialog, although it is running in separate thread. Why do I see a frozen Progress dialog? Why the slot PBoutput is not called although debug shows that thread has emited ShowPB() signal.

    Help,
    Dove17
    Last edited by wysota; 8th April 2010 at 20:33. Reason: missing [code] tags

  2. #2
    Join Date
    Feb 2010
    Location
    Pennsylvania, USA
    Posts
    36
    Thanks
    9
    Thanked 3 Times in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Progress Bar Dialog using threads

    What are the max/min sizes for your progress bar? If you have both set to zero, you'll get a marque-style progress bar. If you have them set to different values, you have to update the value of your progress bar to change it. I think your PBoutput should look more like:
    Qt Code:
    1. void pBarDialog::PBoutput()
    2. {
    3. ui.pBar->setValue(ui.pBar->value() + 1); // your increments may be different.
    4. }
    To copy to clipboard, switch view to plain text mode 
    You could also change your signal to provide the increment amount, or even the full value.

  3. #3
    Join Date
    Apr 2010
    Posts
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Progress Bar Dialog using threads

    The progress Bar min and max are set to (0,0). The Slot PBoutput() is never getting called although the signal emit ShowPB() is emited. The frozen progress bar which i see is coming from the lines
    if(myProBarDialog == NULL) {
    myProBarDialog = new proBarDialog(this);
    }
    myProBarDialog->show();

    before the thread is called.

    Any ideas , how to make it working ?

    Dove17

  4. #4
    Join Date
    Feb 2010
    Location
    Pennsylvania, USA
    Posts
    36
    Thanks
    9
    Thanked 3 Times in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Progress Bar Dialog using threads

    I can tell you are stripping your code down to bare minimum to put on the forums, and that is fine and quite understandable, but we are missing a lot of valuable information. If you could please include your headers, we can see how you are defining your signals, slots, members, etc., which will help us understand your code better, which will allow us to help you better.

    That being said, I just noticed a discrepancy in your code.
    Qt Code:
    1. myProBarDialog = new proBarDialog(this);
    To copy to clipboard, switch view to plain text mode 
    as compared to your apparent class name, "pBarDialog". You will need to instantiate with the appropriate class name:
    Qt Code:
    1. myProBarDialog = new pBarDialog(this);
    To copy to clipboard, switch view to plain text mode 

    Aside: I also noticed you are not deleting your "mProgressBarDialog". By setting the pointer to NULL, you are changing where it's pointing, but not de-allocating the memory you grabbed when calling new. The memory leak would be small, but it is still a leak.

Similar Threads

  1. How to blur parent dialog when child dialog is displayed
    By abhilashajha in forum Qt Programming
    Replies: 4
    Last Post: 10th June 2009, 13:01
  2. Replies: 4
    Last Post: 11th March 2008, 11:44
  3. Draw on a Progress Bar
    By fruzzo in forum Qt Programming
    Replies: 1
    Last Post: 8th December 2007, 15:31
  4. Reg - Progress bar
    By suresh in forum Qt Programming
    Replies: 1
    Last Post: 12th December 2006, 15:11
  5. progress DIalog
    By mickey in forum Newbie
    Replies: 2
    Last Post: 26th July 2006, 14:30

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.