Your main window doesn't show because it is not even constructed at the time you fail to open the database. Your attempt to close the un-constructed window may schedule a close event but it will almost certainly be followed nearly immediately with the show event scheduled in your main().
You need to schedule the attempt to open the database for a point in time after the main window is constructed and visible. You can do this with a zero length, single shot timer. Convert you existing connectDatabase() to a slot and make your constructor look like this:
MainWindow
::MainWindow(QWidget *parent
) : ui(new Ui::MainWindow)
{
ui->setupUi(this);
QTimer::singleShot(0,
this,
SLOT(connectDatabase
()));
}
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
QTimer::singleShot(0, this, SLOT(connectDatabase()));
}
To copy to clipboard, switch view to plain text mode
The window will finish construction, return to the main event loop and be shown before the timer fires. When the timer event is processed the connection error should function as you expect.
Bookmarks