PDA

View Full Version : qprogressDialog



mickey
15th July 2006, 01:30
hi, I'm trying using QProgress dialog but the problem is that the dialog appear, the operation is completed (I can see the result), and dialog is again opem and progress bar have to start again;why? thanks


//steps*100=6400; I choose a casual number (can it be ok?)
LongOperationTodo ();
myProgressDialog* progress = new myProgressDialog (steps*100, this, "progress", TRUE );
progress->setMinimumDuration(1);
for ( int i = 0; i < steps*100; i++ ) {
progress->setProgress( i );
qApp->processEvents();
if ( progress->wasCanceled() )
break;
}
progress->setProgress(steps);

jpn
15th July 2006, 09:09
The way you are using the progress dialog is a bit wrong. You need to 1) call QApplication::processEvents() and 2) advance the progress bar DURING the long operation, not after it.

mickey
15th July 2006, 12:15
I call qApp->process().....but how to call progress DURING? LongOperationTodo (); is a function that call other function; during want mean before??? so I think It'll the same...i'm confused...

mickey
16th July 2006, 15:51
hi, my problem is this: I call render pixmap and it take a long time; where do I have to call processEvents? Every examples I saw, insert it in a for; but I haven't it....thanks



mainform::render() {
qApp->processEvents();
widget->renderPixmap()
}

jpn
16th July 2006, 21:05
hi, my problem is this: I call render pixmap and it take a long time; where do I have to call processEvents? Every examples I saw, insert it in a for; but I haven't it....thanks
Yes, that's the intended usage. There are sometimes lengthy tasks (like calculating of something and so on) which prevent the execution from returning to the application's event loop and so the application cannot process it's move/update/whatever events coming from the underlying system. This is what makes the application unresponsive during a lengthy task unless you call QApplication::processEvents() and let the application to process it's events every now and then.

It's a bit problematic when the lengthy task isn't written by you. You cannot get QApplication::processEvents() called (nor a progress dialog advanced) during for example like in your situation, just a single library call. One option is to move the code calling that library function to another thread. But unfortunately in your situation it might be impossible since you really shouldn't touch widgets in another than the main GUI thread.

I have come to a conclusion that you don't have many options here. Maybe you could just inform the user about what's going to happen: "Saving the image. Please be patient." :)

Btw, have you tried setting useContext as TRUE when calling QGLWidget::renderPixmap()? I'm not sure about it's risks, but it promises to be more efficient.. :)

mickey
17th July 2006, 15:16
but the dialog must be called beofe or after renderPixmap(); this doesn't change the thing, I guess....that's incredibile....thanks