Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. GUI closes
Qt 6.11 is out! See what's new in the release blog

GUI closes

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 489 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    MrDFL
    wrote on last edited by
    #1

    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();
    
    }
    
    1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Moderators Qt Champions 2024 Qt Champions 2022 Qt Champions 2017
      wrote on last edited by
      #2

      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.

      Dheerendra
      @Community Service
      Certified Qt Specialist
      https://www.pthinks.com

      1 Reply Last reply
      4
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        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.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        1

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved