this->close is not working correctly
-
Hey,
I have a problem whereas I know this->close closes the current window
I have created a another window in qt and I have to close the another window when user press a button but what happen is that it's close the current window as well as mainwindow and I only want to close the current one.
Here is the piece of codeif(!exist(new_player,out_dup)){ out << new_player; file.flush(); file.close(); this->close();'Thanks in advance
-
You dont need to "convert" anything.
QMainWindowis just a regularQWidget, extended withQToolBarsand other stuff.
So you can pass aparentQWidgetto the c'tor.For example you could create both widgets in your
main.cpp, pass the parent with the MainWindow c'tor and show the Login form.Edit:
I'm assuming you what to do something like this, since your 2nd widget is calledLogin.:There are so many examples out there...
(If you do it like this, they both can be independent widgets. Then you dont even need a parent / child relation. It's all about a good design / structure.) -
Hey,
I have a problem whereas I know this->close closes the current window
I have created a another window in qt and I have to close the another window when user press a button but what happen is that it's close the current window as well as mainwindow and I only want to close the current one.
Here is the piece of codeif(!exist(new_player,out_dup)){ out << new_player; file.flush(); file.close(); this->close();'Thanks in advance
@UG-SEP said in this->close is not working correctly:
this->close();
So "this" is here the "other window", not main window?
-
@UG-SEP said in this->close is not working correctly:
this->close();
So "this" is here the "other window", not main window?
-
@jsulm yes currently this is here the second window and when I close it the first one also closed
-
Here is the Main Window @jsulm
ui->setupUi(this); this->hide(); Login log; log.setModal(true); log.exec(); this->show();And well I did think that the program crashed because the application output show that the program exited with code(0) means runs successfully
-
Here is the Main Window @jsulm
ui->setupUi(this); this->hide(); Login log; log.setModal(true); log.exec(); this->show();And well I did think that the program crashed because the application output show that the program exited with code(0) means runs successfully
-
@jsulm said in this->close is not working correctly:
How does it behave if you do not hide the main window?
The all works as expected:
https://doc.qt.io/qt-5/qguiapplication.html#quitOnLastWindowClosed-prop
-
@jsulm said in this->close is not working correctly:
How does it behave if you do not hide the main window?
The all works as expected:
https://doc.qt.io/qt-5/qguiapplication.html#quitOnLastWindowClosed-prop
@Christian-Ehrlicher The main window was not closed, just hidden.
-
@Christian-Ehrlicher The main window was not closed, just hidden.
-
Hi,
If you only have one top level widget visible and close it, then the application will stop. As @Christian-Ehrlicher already pointed out, it's the normal behaviour.
-
@jsulm It is closed because the Application Output give the output:
13:41:39: E:\Qt in c++\Projects in Qt\build-BlackJack-Desktop_Qt_6_0_4_MinGW_64_bit-Debug\debug\BlackJack.exe exited with code 0@UG-SEP Yes, see the link @Christian-Ehrlicher posted, especially this part: "If this property is true, the applications quits when the last visible primary window". So, is this property set to true?
-
@UG-SEP Yes, see the link @Christian-Ehrlicher posted, especially this part: "If this property is true, the applications quits when the last visible primary window". So, is this property set to true?
@jsulm said in this->close is not working correctly:
So, is this property set to true?
Yes since it was not set to false :)
-
@jsulm said in this->close is not working correctly:
So, is this property set to true?
Yes since it was not set to false :)
@Christian-Ehrlicher said in this->close is not working correctly:
Yes since it was not set to false :)
How do you know? :-)
-
@Christian-Ehrlicher said in this->close is not working correctly:
Yes since it was not set to false :)
How do you know? :-)
@jsulm said in this->close is not working correctly:
How do you know? :-)
Since the default is true and I'm pretty sure it's not modified here.
-
@jsulm, @Christian-Ehrlicher, @SGaist
ui->setupUi(this); QGuiApplication::setQuitOnLastWindowClosed(false); Login log; log.setModal(true); log.exec();I set it false but then also it the behaviour didn't changed
-
As it seems this second dialog is opened in the ctor of the first... strange idea. How should this work at all?
Move it out of the ctor, check the return value and oen (or not) the mainwindow afterwards. -
As it seems this second dialog is opened in the ctor of the first... strange idea. How should this work at all?
Move it out of the ctor, check the return value and oen (or not) the mainwindow afterwards.@Christian-Ehrlicher ok as I will do it right now but can you tell me that how can I convert the base main window.CPP as child and Second Window as parent
-
@Christian-Ehrlicher ok as I will do it right now but can you tell me that how can I convert the base main window.CPP as child and Second Window as parent
You dont need to "convert" anything.
QMainWindowis just a regularQWidget, extended withQToolBarsand other stuff.
So you can pass aparentQWidgetto the c'tor.For example you could create both widgets in your
main.cpp, pass the parent with the MainWindow c'tor and show the Login form.Edit:
I'm assuming you what to do something like this, since your 2nd widget is calledLogin.:There are so many examples out there...
(If you do it like this, they both can be independent widgets. Then you dont even need a parent / child relation. It's all about a good design / structure.)