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.
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.
Does the thread know how much it is left for it to do?
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
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%
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.
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 )
sounds okay to me , it will do the job in a descent wayIf 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.
Thanks for your help.
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:
{ Q_OBJECT public: explicit ThreadProgressDialog(QWidget* parent = 0) : QProgressDialog(parent), m_timer(new QTimer(this)) { setRange(0, 0); m_timer->setInterval(500); connect(m_timer, SIGNAL(timeout()), this, SLOT(advance())); } public slots: void threadStarted() { m_timer->start(); show(); } void threadFinished() { m_timer->stop(); hide(); } private: QTimer *m_timer; private slots: void advance() { setValue(value() + 1); } };To copy to clipboard, switch view to plain text mode
And then connect the thread's signals to the respective dialog slot.
Cheers,
_
toufic.dbouk (12th September 2013)
I suggested using minimum=value=maximum=0 which should get the special behaviour of the progress dialog without the need for setting a value.
toufic.dbouk (12th September 2013)
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,
_
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.
Bookmarks