How to quit Application immedialy after QMessageBox?
Unsolved
General and Desktop
-
I would like detect current running Windows Version, if it is Windows Server then close application immedialy, qApp->exit(); does not seem have effect here.
#include "mainwindow.h" #include <QApplication> int main(int argc, char *argv[]) { QApplication a(argc, argv); MainWindow w; w.show(); return a.exec(); }
#ifndef MAINWINDOW_H #define MAINWINDOW_H #include <QMainWindow> QT_BEGIN_NAMESPACE namespace Ui { class MainWindow; } QT_END_NAMESPACE class MainWindow : public QMainWindow { Q_OBJECT public: MainWindow(QWidget *parent = nullptr); ~MainWindow(); private: Ui::MainWindow *ui; }; #endif // MAINWINDOW_H
#include "mainwindow.h" #include <QMessageBox> #include "ui_mainwindow.h" MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) , ui(new Ui::MainWindow) { ui->setupUi(this); if ( QSysInfo::prettyProductName().contains( "Server" ) ) { QMessageBox::information( Q_NULLPTR, "Test Mode", "It is : " + QSysInfo::prettyProductName() ); // Windows 10 qApp->exit(); } } MainWindow::~MainWindow() { delete ui; }
-
Or just don't put that check code in the main window constructor and structure your app better. It doesn't look like it has anything to do with that window, so why is it in it, i.e.
int main(int argc, char *argv[]) { QApplication a(argc, argv); if ( QSysInfo::prettyProductName().contains( "Server" ) ) { QMessageBox::information( Q_NULLPTR, "Test Mode", "It is : " + QSysInfo::prettyProductName() ); // Windows 10 return 0; } MainWindow w; w.show(); return a.exec(); }
-
Nice tipps, thx, I just began this way, forgot to put QApplication to first line