I haven't tried this in anger but the C++ GUI Programming with Qt 4, Second Edition uses his trick in the constructor:
MainWindow::MainWindow()
{
...
QTimer::singleShot(0,
this,
SLOT(openConnection
()));
}
MainWindow::MainWindow()
{
...
QTimer::singleShot(0, this, SLOT(openConnection()));
}
To copy to clipboard, switch view to plain text mode
to move a potential long-running init process out of the constructor and allow the GUI to draw so the user doesn't think the program has hung. The zero time out causes the QTimer to fire when the event loop is idle. The openConnection() can then take quite a while if needed, or in your case of a failure, pop-up an error message before calling close().
Bookmarks