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

exe closes immediately after compiling

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 1.9k Views 2 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.
  • A Offline
    A Offline
    Allerknappe
    wrote on last edited by A Former User
    #1

    Hello,

    I have a question about my programm.
    After compiling it, i only see a few moment a graphical interface and then the programm will closed.
    I tryed to copy some synthax from working example code but it seems that i have somewhere do a mistake...
    I thinkt it´s not a hard problem, but for hel i´m really grateful.
    Here a snippet of my code:

    //main.h , in my case it will open the NeuLoad case:
    
    #include <QApplication>
    #include "Hauptmenu.h"
    #include "Funktionen.h"
    
    int main(int argc, char *argv[] )
    {
    	QApplication app(argc,argv);
    	Funktionen funktionen;	
    	if(funktionen.FolderCheck()==true)
    	{
    		Hauptmenu window;
    		window.show();
    	}
    	
    	else
    	{
    		NeuLoad window2;
    		window2.show();
    	}
    	
    	return app.exec();
    }
    
    //NeuLoad.h
    
    #ifndef NEULOAD_H
    #define NEULOAD_H
    #include <QtGui>
    #include <QDialog>
    #include <QMessageBox>
    #include "ui_NeuLoad.h"
    
    class NeuLoad : public QDialog, private Ui::NeuLoad
    {
    	Q_OBJECT
    	
    	public:
    		NeuLoad();
    		~NeuLoad() {}
    	protected slots:
    		void openHauptmenu();
    		void openFreischaltcode();
    	
    		
    	
    };
    #endif // NEULOAD_H
    

    and the NeuLoad.cpp:

    //NeuLoad.cpp
    
    #include "NeuLoad.h"
    #include "Hauptmenu.h"
    #include "Freischaltcode.h"
    
    NeuLoad::NeuLoad()
    {
    		
    	setupUi(this);	
    
    //Bereich für Signal Slot Verbindungen:
    connect(neu, SIGNAL(clicked()),	
    		this, SLOT(openHauptmenu()));			//Button neu ruft Hauptmenü auf
    			
    connect(best, SIGNAL(clicked()),	
    		this, SLOT(openFreischaltcode()));		//Button best ruft Freischaltcodemenü auf
    }
    	
    void NeuLoad::openHauptmenu()
    {
    	
    	Hauptmenu *HaMenu = new Hauptmenu();
    	HaMenu->show();
    }
    	
    void NeuLoad::openFreischaltcode()
    {
    	Freischaltcode *FrMenu = new Freischaltcode();
    	FrMenu->show();
    }
    

    Thank you for your help.

    greetings
    Allerknappe

    [Edit: fixed markup ~~ @Wieland]

    ? 1 Reply Last reply
    0
    • A Allerknappe

      Hello,

      I have a question about my programm.
      After compiling it, i only see a few moment a graphical interface and then the programm will closed.
      I tryed to copy some synthax from working example code but it seems that i have somewhere do a mistake...
      I thinkt it´s not a hard problem, but for hel i´m really grateful.
      Here a snippet of my code:

      //main.h , in my case it will open the NeuLoad case:
      
      #include <QApplication>
      #include "Hauptmenu.h"
      #include "Funktionen.h"
      
      int main(int argc, char *argv[] )
      {
      	QApplication app(argc,argv);
      	Funktionen funktionen;	
      	if(funktionen.FolderCheck()==true)
      	{
      		Hauptmenu window;
      		window.show();
      	}
      	
      	else
      	{
      		NeuLoad window2;
      		window2.show();
      	}
      	
      	return app.exec();
      }
      
      //NeuLoad.h
      
      #ifndef NEULOAD_H
      #define NEULOAD_H
      #include <QtGui>
      #include <QDialog>
      #include <QMessageBox>
      #include "ui_NeuLoad.h"
      
      class NeuLoad : public QDialog, private Ui::NeuLoad
      {
      	Q_OBJECT
      	
      	public:
      		NeuLoad();
      		~NeuLoad() {}
      	protected slots:
      		void openHauptmenu();
      		void openFreischaltcode();
      	
      		
      	
      };
      #endif // NEULOAD_H
      

      and the NeuLoad.cpp:

      //NeuLoad.cpp
      
      #include "NeuLoad.h"
      #include "Hauptmenu.h"
      #include "Freischaltcode.h"
      
      NeuLoad::NeuLoad()
      {
      		
      	setupUi(this);	
      
      //Bereich für Signal Slot Verbindungen:
      connect(neu, SIGNAL(clicked()),	
      		this, SLOT(openHauptmenu()));			//Button neu ruft Hauptmenü auf
      			
      connect(best, SIGNAL(clicked()),	
      		this, SLOT(openFreischaltcode()));		//Button best ruft Freischaltcodemenü auf
      }
      	
      void NeuLoad::openHauptmenu()
      {
      	
      	Hauptmenu *HaMenu = new Hauptmenu();
      	HaMenu->show();
      }
      	
      void NeuLoad::openFreischaltcode()
      {
      	Freischaltcode *FrMenu = new Freischaltcode();
      	FrMenu->show();
      }
      

      Thank you for your help.

      greetings
      Allerknappe

      [Edit: fixed markup ~~ @Wieland]

      ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2
      if ( ... )
      { 
          // local scope begins here 
          Hauptmenu window; // create window in local scope 
          ...
          // local scope ends, window gets destroys	
      }
      

      Hi! Your windows are created in the local scope of your if statement. Thus they are created on the stack and get destroyed once the control leaves the local scope.

      1 Reply Last reply
      3
      • A Offline
        A Offline
        Allerknappe
        wrote on last edited by
        #3

        ah ok so easy... thank you for help

        1 Reply Last reply
        0
        • Pablo J. RoginaP Offline
          Pablo J. RoginaP Offline
          Pablo J. Rogina
          wrote on last edited by
          #4

          @Allerknappe if your problem is solved, could you please mark your post as such? Thanks.

          Upvote the answer(s) that helped you solve the issue
          Use "Topic Tools" button to mark your post as Solved
          Add screenshots via postimage.org
          Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

          1 Reply Last reply
          0

          • Login

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