PDA

View Full Version : how to show the progres of an operation without any loops



franco.amato
12th March 2010, 23:44
Hi I would show the progress of an operation in the case I don't have a loop with iterations.

for example:


....code...
bool ret = routine( some param ); //this take long time
...more code

How can I inform the user that the program is not blocked in this case?
The QProgressDialog need a loop with some iterations to be updated and is not my case.

Best Regards

user_mail07
13th March 2010, 00:08
You can use QTimer. If you dont wanna use iterations you can use QProcess also. When process will be exited there is signal called ProcessExited() will be triggered and you can stop timer at that time. Mean while if you want to display progressBar to let user know that something is going on the background and update progressbar so on.
connect(m_pTimer, SIGNAL(timeout()), this, SLOT(Somemethod()));

franco.amato
13th March 2010, 01:28
You can use QTimer. If you dont wanna use iterations you can use QProcess also. When process will be exited there is signal called ProcessExited() will be triggered and you can stop timer at that time. Mean while if you want to display progressBar to let user know that something is going on the background and update progressbar so on.
connect(m_pTimer, SIGNAL(timeout()), this, SLOT(Somemethod()));

Sorry but I don't understand.
QProcess is not used to start an external program? How can I use it in this case?

yogeshgokul
13th March 2010, 10:56
Sorry but I don't understand.
QProcess is not used to start an external program? How can I use it in this case?

QProcess can start an external process very well. And user_mail07's solution is good for your case.
If you haven't written the code of the process, then you have no idea about the status of the process, means its still running or its completed. So QProcess gives you the virtual power to get noticed when the process is done.
So use of QTimer from start of QProcess, and till QProcess ends, and showing the QProgressBar inbetween will do the trick.
However you will never know the actual status of the process untill your process is not returning any signal or notification about the current status.

Lykurg
13th March 2010, 13:10
You can use QProcess only to start an external process. Not to du it with a member function. So I would go with a QProgressDialog which only shows a busy bar (without indicating how long something will take time, and start the function via QtConcurrentRun, that will keep your gui respondable.

franco.amato
13th March 2010, 13:51
You can use QProcess only to start an external process. Not to du it with a member function. So I would go with a QProgressDialog which only shows a busy bar (without indicating how long something will take time, and start the function via QtConcurrentRun, that will keep your gui respondable.

Hi Lykurg,
thank you. Can you help me with some lines of code?

Regards

squidge
13th March 2010, 17:55
Put your routine into a thread. When the thread completes, send a signal to your main app (signal/slot mechanism). Whilst that is happening in the background, you can use things like QProgressDialog or others.

franco.amato
14th March 2010, 04:30
Put your routine into a thread. When the thread completes, send a signal to your main app (signal/slot mechanism). Whilst that is happening in the background, you can use things like QProgressDialog or others.

Some code please?

Thanx in advance

wysota
14th March 2010, 08:34
Some code please?
Here we go again...

Moving the thread to "Newbie", it's obviously a newbie problem.

franco.amato
16th March 2010, 06:20
Here we go again...

Moving the thread to "Newbie", it's obviously a newbie problem.

Wysota what's for newbie and for not-newbie for you? For me, and I'm sure for others users, is not so obviously

wysota
16th March 2010, 08:50
Wysota what's for newbie and for not-newbie for you? For me, and I'm sure for others users, is not so obviously

Constantly asking for working code is definitely newbie. Trust me, it's better this way - people have much more patience for people writing in the newbie section than for those claming to be "programmers".