exe closes immediately after compiling



  • 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]


  • Moderators

    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.



  • ah ok so easy... thank you for help



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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.