Reputation: 656
I have a desktop application that I'm building which checks a QSetting
value and if it isn't set shows one QMainWindow
class but if it is, shows a different QMainWindow
class. The two classes are literally identical at this point as it's early on and don't really contain anything.
In my main
function this is what I've got:
int main (int argc, char *argv[]) {
...
if (userToken == "NO_USER") {
LoginWindow w;
w.show();
} else {
MainWindow w;
w.show();
}
return a.exec();
}
The only difference in this between the default project set up from when I created the project is the addition of the conditional window load. Both MainWindow
and LoginWindow
don't have anything loading other than the ui file associated with them, they're functionally the same.
The weirdness is if I do w.showFullScreen()
for the LoginWindow
it will show up and take up the whole screen, if I do w.show()
nothing at all happens, no compiler warnings|errors, application runs fine, just no window displays.
If I remove the conditional statements and LoginWindow
references, MainWindow shows up fine.
Any idea why a call to .showFullScreen()
would work but a call to .show()
on the same class wouldn't?
Upvotes: 1
Views: 503
Reputation: 9688
I am not sure if this solves you problem, but there definitely is a bug in your code. You are instanciating the window objects on the stack inside a a tight scope, and as you know those objects will be destructed as soon as they go out of that scope. What you are doing is letting them go out of scope before the application is ever started.
Please try this instead:
int main (int argc, char *argv[]) {
...
if (userToken == "NO_USER") {
LoginWindow w;
w.show();
return a.exec();
} else {
MainWindow w;
w.show();
return a.exec();
}
}
Upvotes: 0