I have a Qt application that uses a QMainWindow
-derived class for the main UI. On startup I want to make some security checks and, if they fail, display a message to the user and close the main window. Currently I make these checks in the QMainWindow
constructor, but if I call the close
method, nothing happens and the application continues to run. For example:
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
{
setupUi(this);
...
if (checkFails())
{
QMessageBox::warning(this, tr("Error"), tr("You cannot run this app"));
// This has no effect
close();
}
}
Alternatively I could make the checks in the main function but then I lose the ability to display a language-specific message box (the tr
macro only works in a QObject
-derived class by the looks of things.)
Any ideas on how to close the main window on startup or make the tr
macro work outside of a QObject
derived class?