PDA

View Full Version : use QDialog to show file name



damonlin
15th November 2008, 08:23
Dear All:
I subclass QDialog which includes a QLabel and a QProgressBar.
QLabel is about to show deleting file name and QProgreeBar is for progress.
But Dialog seems to busy if you call QLabel ::setText(),
it'll ok if you call QProgreeBar::setValue();

I doubt "model()->filename(iIdx).filePath()" takes more execution time ...:confused:

I use recursive to implement deleting function, for example

int file_recursive_delete(QModelIndex iIdx)
{
// it'll call QLabel ::setText(), but Dialog won't update text until deleting is finished
emit notifyFileNameToProgress( model()->filename(iIdx).fileName() );

// it'll call QProgreeBar::setValue(), and it works....Dialog won't busy....
emit notifyValueToProgress();

// ...... do deleting
}

wysota
16th November 2008, 09:54
First of all take a look at QProgressDialog. Second of all, if you want the progress bar to redraw itself after you update its value, you have to let your application process its events, for instance by calling sendPostedEvents() or QCoreApplication::processEvents().

damonlin
16th November 2008, 12:18
Thank you so much .....:D
I add processEvents() in the subclass and worked correctly
I wonder why I have to add processEvents().
Is it because the UI is too busy to process the slot ??

wysota
16th November 2008, 13:52
Qt only processes events when the control returns to the event loop. When you are inside any function you write yourself (like a slot or event handler) the control is not in the event loop but in your function, hence other events are not processed. Qt doesn't use external threads to process events, so there is no magical way of having the events processed other than to request it yourself, for example with processEvents(). If you are a commercial Qt user, you can read an article about it in the latest (#27) Qt Quarterly.