Results 1 to 12 of 12

Thread: is it possible to relate a QprogressDialog or a QProgressBar to a thread's execution?

  1. #1
    Join Date
    Dec 2012
    Posts
    197
    Thanks
    25
    Thanked 41 Times in 33 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default is it possible to relate a QprogressDialog or a QProgressBar to a thread's execution?

    Hello everyone,
    is there a way to connect a QProgressDialog or QProgressBar to the execution of a QThread?
    for example the QProgressDailog should appear when the QThread starts and then show the progress until the QThread finishes.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: is it possible to relate a QprogressDialog or a QProgressBar to a thread's execut

    Does the thread know how much it is left for it to do?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Dec 2012
    Posts
    197
    Thanks
    25
    Thanked 41 Times in 33 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: is it possible to relate a QprogressDialog or a QProgressBar to a thread's execut

    The thread is executing a query so im guessing no it doesn't know how much is left
    unless there is an option in QSqlQuery to show the progress of a query being executed

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: is it possible to relate a QprogressDialog or a QProgressBar to a thread's execut

    Quote Originally Posted by toufic.dbouk View Post
    The thread is executing a query so im guessing no it doesn't know how much is left
    So it can't show its progress, can it?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Dec 2012
    Posts
    197
    Thanks
    25
    Thanked 41 Times in 33 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: is it possible to relate a QprogressDialog or a QProgressBar to a thread's execut

    I dont know :P your are the expert here im asking for your assistance
    ill try to work on it and get back to you ,
    but i was wondering if we could just connect the QThread start method to the the QProgressDialog and show some slow progress
    and connect the QThread exit or finish method to the QProgressDialog so that when the thread is done we can just speed up the progress and finish it to 100%

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: is it possible to relate a QprogressDialog or a QProgressBar to a thread's execut

    Quote Originally Posted by toufic.dbouk View Post
    but i was wondering if we could just connect the QThread start method to the the QProgressDialog and show some slow progress
    There is no concept of "progress" with a thread.

    If you want to show the user some information that the program is busy then show a progress dialog, set its minimum, maximum and value properties to 0 and show the dialog. When you get a finished signal from the thread, invoke the hide() slot of the dialog.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7
    Join Date
    Dec 2012
    Posts
    197
    Thanks
    25
    Thanked 41 Times in 33 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: is it possible to relate a QprogressDialog or a QProgressBar to a thread's execut

    Quote Originally Posted by wysota View Post
    There is no concept of "progress" with a thread.
    i didnt mean progress of the thread , i mean just show some random progress of the QProgressDialog ( as if the bar is just getting filled from 0 to 100 )

    If you want to show the user some information that the program is busy then show a progress dialog, set its minimum, maximum and value properties to 0 and show the dialog. When you get a finished signal from the thread, invoke the hide() slot of the dialog.
    sounds okay to me , it will do the job in a descent way

    Thanks for your help.

  8. #8
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: is it possible to relate a QprogressDialog or a QProgressBar to a thread's execut

    I think you will still need to drive the progress by calling setValue() but that should be easy with a timer.

    I.e. like this
    Qt Code:
    1. class ThreadProgressDialog : public QProgressDialog
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6. explicit ThreadProgressDialog(QWidget* parent = 0) : QProgressDialog(parent), m_timer(new QTimer(this)) {
    7. setRange(0, 0);
    8. m_timer->setInterval(500);
    9. connect(m_timer, SIGNAL(timeout()), this, SLOT(advance()));
    10. }
    11.  
    12. public slots:
    13. void threadStarted() {
    14. m_timer->start();
    15. show();
    16. }
    17.  
    18. void threadFinished() {
    19. m_timer->stop();
    20. hide();
    21. }
    22.  
    23. private:
    24. QTimer *m_timer;
    25.  
    26. private slots:
    27. void advance() {
    28. setValue(value() + 1);
    29. }
    30. };
    To copy to clipboard, switch view to plain text mode 

    And then connect the thread's signals to the respective dialog slot.

    Cheers,
    _

  9. The following user says thank you to anda_skoa for this useful post:

    toufic.dbouk (12th September 2013)

  10. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: is it possible to relate a QprogressDialog or a QProgressBar to a thread's execut

    I suggested using minimum=value=maximum=0 which should get the special behaviour of the progress dialog without the need for setting a value.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  11. The following user says thank you to wysota for this useful post:

    toufic.dbouk (12th September 2013)

  12. #10
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: is it possible to relate a QprogressDialog or a QProgressBar to a thread's execut

    Quote Originally Posted by wysota View Post
    I suggested using minimum=value=maximum=0 which should get the special behaviour of the progress dialog without the need for setting a value.
    Are you sure you don't have to do anything else?
    I might remember incorrectly but setting the range 0,0 is only switching the mode from "normal prgress" to "bounce left/right, unknown duration", but without calling setValue the bar will not change.

    Hence my example using both

    Cheers,
    _

  13. #11
    Join Date
    Dec 2012
    Posts
    197
    Thanks
    25
    Thanked 41 Times in 33 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: is it possible to relate a QprogressDialog or a QProgressBar to a thread's execut

    Quote Originally Posted by anda_skoa View Post
    I might remember incorrectly but setting the range 0,0 is only switching the mode from "normal prgress" to "bounce left/right, unknown duration", but without calling setValue the bar will not change.
    yea thats exactly the purpose of it to just bounce left and right without stopping , to show the user that something is loading and then just hide or close it when the executing process is done.
    your example is great Im sure im gonna use it soon but for now this just gets the job done with 3 lines of code
    Thanks for your reply.

  14. #12
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: is it possible to relate a QprogressDialog or a QProgressBar to a thread's execut

    Quote Originally Posted by anda_skoa View Post
    Are you sure you don't have to do anything else?
    I might remember incorrectly but setting the range 0,0 is only switching the mode from "normal prgress" to "bounce left/right, unknown duration", but without calling setValue the bar will not change.

    Hence my example using both
    If minimum and maximum are set to both 0, then setting the value to anything other shouldn't have any effect as the value should be bound to min <= val <= max. At least that's my logic
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. QTcpSocket and QProgressBar/QProgressDialog
    By nikkadim in forum Qt Programming
    Replies: 8
    Last Post: 20th September 2012, 12:47
  2. Does "emit" in the calling thread mean execution?
    By nomadoro in forum Qt Programming
    Replies: 3
    Last Post: 23rd September 2009, 12:16
  3. Use of QProgressBar in Thread
    By merry in forum Qt Programming
    Replies: 2
    Last Post: 5th January 2009, 22:53
  4. Need help in QProgressDialog
    By santhoshv84 in forum Qt Programming
    Replies: 3
    Last Post: 12th September 2008, 19:24
  5. qprogressDialog
    By mickey in forum Qt Programming
    Replies: 5
    Last Post: 17th July 2006, 15:16

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.