Problem using the if...else structure in main.cpp
-
Im trying to use the if else structure to control which form is shown before the main window. The app first checks if a file named add.txt is present then shows thecorrect form. Here's my code:
@
//a continuation of the main.cppif (0 == access ("C:/Microsoft/add.txt",0))
(MainWindow z;
z.show();
}else {
window2 y;
y.show();
}return a.exec();
}
@However, the window just blinks and runs in the background with no UI. How do I make it run correctly by showing the UI??
[EDIT: code formatting, please wrap in @-tags, Volker]
-
Both z and y are declared inside the block where you call show on them. Once you leave that block they are going out and are destroyed.
-
I would rewrite it as something like:
@
//a continuation of the main.cppMainWindow *z = 0;
window2 *y = 0;if (0 == access ("C:/Microsoft/add.txt",0))
z = new MainWindow();
z->show();
} else {
y = new window2();
y->show();
}return a.exec();
}
@Brain to terminal; ymmv