PDA

View Full Version : flush draw events



rbp
18th March 2009, 06:39
hello,

In my program the user chooses a file with QFileDialog::getOpenFileName() and then a heavy operation gets performed on that file.
My problem is that the dialog is still partly visible during the heavy operation.

What is a good strategy to make sure the dialog is completely hidden before I start the heavy operation? Is there a way to flush all the draw events. Or do I need to wait some milliseconds?

I'm sure this problem is common but I didn't notice anything useful in the QWidget API or this forum.

Richard

munna
18th March 2009, 06:47
QFileDialog::getOpenFileName() returns the path to the existing file. The file dialog should be hidden as soon as the path is returned. The operation that you perform on the file should not be the reason for the dialog still being visible.

Can you post the code here for better understanding of the problem?

rbp
18th March 2009, 07:53
By partially visible I mean the background widget has not refreshed properly so the dialog is still visible. Do you know a way to flush all pending draw events?

The relevant code:

QString file = QFileDialog::getOpenFileName(this, "Select file");
doHeavyEvent(file);

spirit
18th March 2009, 08:02
try to add qApp->processEvent(); in doHeavyEvent(file); or move "havy operations" in worker thread. first approach is simpler.

rbp
19th March 2009, 01:35
thanks spirit. I couldn't easily get a reference to the application variable but fortunately processEvents() is static:

QCoreApplication::processEvents();

wysota
19th March 2009, 01:37
The application object is globally available through a "qApp" variable or using QCoreApplication::instance() static call.

rbp
19th March 2009, 02:31
oh really, I didn't realize Qt exposed global references. Is there a list available of the global variables in Qt?

wysota
19th March 2009, 10:14
Actually in Qt4 qApp is not a global variable but a macro that expands to QCoreApplication::instance() (or QApplication::instance(), depending which header file you included).