View Full Version : QFileDialog won't close when I tell it to
Compeau
10th August 2010, 16:09
I create a QFileDialog, call getOpenFileName on it, then try to close it. After that, I open the file in my code (which takes a while). My problem is that the QFileDialog doesn't close until after my code to open the file completes. Why is this? If I try to change the cursor on the QFileDialog to the WaitCursor, it doesn't take affect until after the open operation completes.
How do I get this QFileDialog to close right after getting a filename, or at least display the WaitCursor when the 'open' button is pressed?
saa7_go
10th August 2010, 16:46
I create a QFileDialog, call getOpenFileName on it, then try to close it.
Why do you create a QFileDialog object? QFileDialog::getOpenFileName() is a static function.
Lykurg
10th August 2010, 16:46
It's because your following code blocks the GUI thread. After receiving the file call
QCoreApplication::processEvents();and your dialog will close. Also have a look at keeping the GUI responsive. It was an article in Qt Quarterly.
Compeau
10th August 2010, 18:24
It's because your following code blocks the GUI thread. After receiving the file call
QCoreApplication::processEvents();and your dialog will close. Also have a look at keeping the GUI responsive. It was an article in Qt Quarterly.
Thanks! I read the article, and used the following line of code to run my time-consuming open code asynchronously after getting the filename.
QMetaObject::invokeMethod(this, "slot name", Qt::QueuedConnection);
This completely fixed my problem.
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.