QMainWindow Hide( ) and show( )
-
Greetings everyone once again,
so I begin to explore on the show( ) and hide( ) on QMainWindow.
I managed to get the results all these while (Dialog will not pop when hide( ) , etc)However , only today I realised that putting a hide( )0. Meaning to say that it is still running actually and went on to be stucked due to the omitted show( ) .
I removed the " MainWindow w; " and w.show()" from main.cpp so that I can put choices/flexibility in my other .cpp file
//Hide and show void MainWindow::Function(int number){ if (number == 1 ){ MainWindow::show(); } else if (number == 2){ MainWindow::hide(); //Doesnt actually exit the dialog/application with code 0 } }
How can I hide QMainWindow properly if this is the case?
EDIT: Let me rephrase my question since I am more clear with the situation. Since it is hidden, how do I exit if the application/dialog is hidden away from me? Should I just enable a connect button (Connect Esc with Exit())?
-
@Faruq I don't understand the question. hide() does not exit the dialog/application, it just hides the dialog/application window as the name suggests. To exit the application you call http://doc.qt.io/qt-5/qcoreapplication.html#quit (application) or http://doc.qt.io/archives/qt-4.8/qwidget.html#close for dialog.
AlsoMainWindow::show(); MainWindow::hide();
is invalid code as neither show() nor hide() are static, you have to call them on actual QMainWindow instance.
-
@jsulm Ah, I went on to reflect after reading your comment. I understand what is my actual question now.
Let me rephrase my question. Since it is hidden, how do I exit if the application/dialog is hidden away from me from sight? Should I just enable a connect button (Connect Esc with Exit())?
-
@Faruq Do you want that the user exits your app while it is hidden or do you want to exit your app on some condition?
If you want the user to exit your app then it should not be hidden, else user will not see the UI of your app. So, to me the use case is still unclear.
A hidden app is still shown in the taskbar and can be closed from there (right click). -
@jsulm I don't think so. Qt say it crashes when I run the stop button. But I'm sure it's hiding. I'm going to try to connect the Esc button for quit to see if it I indeed on the background or so. Will be back in a while. :) thank you for your patience in guiding me.