Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

GUI closes



  • I'm new to qt my qt GUI closes after running my application

    My code:

    #include "GUI.h"
    #include <QtWidgets/QApplication>
    
    void createGUI(int argc, char* argv[]);
    QApplication* app;
    GUI* gui;
    
    int main(int argc, char *argv[])
    {
    	createGUI(argc, argv);
    	return app->exec();
    }
    
    void createGUI(int argc, char *argv[]) {
    	QApplication a(argc, argv);
    	GUI w;
    	app = &a;
    	gui = &w;
    	w.setWindowFlags(Qt::MSWindowsFixedSizeDialogHint);
    	w.show();
    
    }
    

  • Qt Champions 2017

    You are creating the a & w as local objects. They will be destroyed once the function call is over. Your app is crashing at app-exec() as app object is destroyed once the function call createGUI is complete.


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    In addition to to what @dheerendra wrote, since you are new to Qt, please follow the code examples in the documentation. In none of them you'll see such a way to setup and run a Qt application.


Log in to reply