tags:

views:

51

answers:

1

Create a simple Qt4 Gui Application, surround the window construction and show commands in an if statement and run the application.
When I do this the window flashes for a microsecond and then disappears ... Why?
I'm running Qt Creator 1.2.1, Based on Qt 4.5.2(32 bit), on Windows 7 Pro.

#include <QtGui/QApplication>
#include "mainwindow.h"

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    bool taut = true;
    if ( taut) {
        MainWindow w;
        w.show();
    }
    return a.exec();
}
+8  A: 

The scope of w is within the if statement. The variable is not defined anymore after you leave the last }.

I think this is why the window disappears.

Aziz
Well done, you're quite right.
crowne