Qt app doesn't close properly (still visible in task manager)
-
wrote on 8 Nov 2019, 13:10 last edited by hobbyProgrammer 11 Aug 2019, 14:21
I've written an application, but when I use the close button on the right corner to close the app, the window is invisible, but it's still in my task manager. I am talking about the buttons that Qt provides when you create a window.
I have an app with 3 windows. You need to go through the first window to get the second and you need to get through the second window to get the third. So I'm calling 2 hides, but I would think that if you'd press the close button it would close the entire app.
Is there anyone else having the same issues and if so, how can I solve this?I've set a breakpoint to return a.exec(), but it doesn't go there.
int main(int argc, char *argv[]) { QApplication a(argc, argv); Login login; login.show(); qApp->setQuitOnLastWindowClosed(false); return a.exec(); }
could it be the setQuitOnLastWindowClosed(false) that prevents it from closing?
I need that line to not let my app crash when I show a QMessageBox. -
I've written an application, but when I use the close button on the right corner to close the app, the window is invisible, but it's still in my task manager. I am talking about the buttons that Qt provides when you create a window.
I have an app with 3 windows. You need to go through the first window to get the second and you need to get through the second window to get the third. So I'm calling 2 hides, but I would think that if you'd press the close button it would close the entire app.
Is there anyone else having the same issues and if so, how can I solve this?I've set a breakpoint to return a.exec(), but it doesn't go there.
int main(int argc, char *argv[]) { QApplication a(argc, argv); Login login; login.show(); qApp->setQuitOnLastWindowClosed(false); return a.exec(); }
could it be the setQuitOnLastWindowClosed(false) that prevents it from closing?
I need that line to not let my app crash when I show a QMessageBox.wrote on 8 Nov 2019, 13:40 last edited by@hobbyProgrammer said in Qt app doesn't close properly (still visible in task manager):
qApp->setQuitOnLastWindowClosed(false)
does exactly what it says on the tin! Of course it prevents the application from automatically exiting when the last window is closed! So you'll get the behaviour you describe.
I need that line to not let my app crash when I show a QMessageBox.
No idea what you mean. I cannot imagine you would want to disable auto-closing on last window close, especially as you're complaining about just that keep-running behaviour.
-
I've written an application, but when I use the close button on the right corner to close the app, the window is invisible, but it's still in my task manager. I am talking about the buttons that Qt provides when you create a window.
I have an app with 3 windows. You need to go through the first window to get the second and you need to get through the second window to get the third. So I'm calling 2 hides, but I would think that if you'd press the close button it would close the entire app.
Is there anyone else having the same issues and if so, how can I solve this?I've set a breakpoint to return a.exec(), but it doesn't go there.
int main(int argc, char *argv[]) { QApplication a(argc, argv); Login login; login.show(); qApp->setQuitOnLastWindowClosed(false); return a.exec(); }
could it be the setQuitOnLastWindowClosed(false) that prevents it from closing?
I need that line to not let my app crash when I show a QMessageBox.wrote on 8 Nov 2019, 13:45 last edited by Pl45m4 11 Aug 2019, 13:51Do you use a parent-child structure or three independent windows?
Does your program exits properly, if you close all three windows?
(If a parent window is still running in the background, your program wont exit)EDIT:
@hobbyProgrammer why you removed theqApp->setQuitOnLastWindowClosed(false)
from your post?
This line is not necessary. If it is in your case, your are doing something else wrong.I need that line to not let my app crash when I show a QMessageBox.
Have a look at your three windows, dialogs and messageBoxes again. Try to figure out, what's going wrong there.
-
Do you use a parent-child structure or three independent windows?
Does your program exits properly, if you close all three windows?
(If a parent window is still running in the background, your program wont exit)EDIT:
@hobbyProgrammer why you removed theqApp->setQuitOnLastWindowClosed(false)
from your post?
This line is not necessary. If it is in your case, your are doing something else wrong.I need that line to not let my app crash when I show a QMessageBox.
Have a look at your three windows, dialogs and messageBoxes again. Try to figure out, what's going wrong there.
wrote on 8 Nov 2019, 13:55 last edited byI don't know what I am doing wrong. I followed the examples from the Qt docs.
QMessageBox message; message.setText("QMessageBoxText"); message.setStandardButtons(QMessageBox::Yes | QMessageBox::No); int ret = message.exec(); if(ret == QMessageBox::Yes) { qDebug() << "Yes" } else if(ret == QMessageBox::No) { qDebug() << "No" }
for some reason this closes my entire app, but I can't seem to figure out why.
-
I don't know what I am doing wrong. I followed the examples from the Qt docs.
QMessageBox message; message.setText("QMessageBoxText"); message.setStandardButtons(QMessageBox::Yes | QMessageBox::No); int ret = message.exec(); if(ret == QMessageBox::Yes) { qDebug() << "Yes" } else if(ret == QMessageBox::No) { qDebug() << "No" }
for some reason this closes my entire app, but I can't seem to figure out why.
wrote on 8 Nov 2019, 14:14 last edited by@hobbyProgrammer
It will only close your entire app if you have the defaultsetQuitOnLastWindowClosed(true)
and this message box is the last window your app has open. You should have another window open if you don't want your app to exit. I don't know why you are hiding windows as you go. I don't know what you expect to happen after you close the last window, if you intend the app to continue you would need another window open for the user to do something in.... -
I don't know what I am doing wrong. I followed the examples from the Qt docs.
QMessageBox message; message.setText("QMessageBoxText"); message.setStandardButtons(QMessageBox::Yes | QMessageBox::No); int ret = message.exec(); if(ret == QMessageBox::Yes) { qDebug() << "Yes" } else if(ret == QMessageBox::No) { qDebug() << "No" }
for some reason this closes my entire app, but I can't seem to figure out why.
wrote on 8 Nov 2019, 14:25 last edited byNormally a MessageBox is shown above some parent Widget like
QDialog
,QWindow
orQMainWindow
. If you hide / close all widgets except your MessageBox and close the MessageBox afterwards, your program exits.Maybe you can replace your windows with one or two windows with a widget container like
QStackedWidget
or you replace widgets on runtime. This would reduce the amount of show / hide processes. But depends on you and your needs, what will work best for you. :) -
Normally a MessageBox is shown above some parent Widget like
QDialog
,QWindow
orQMainWindow
. If you hide / close all widgets except your MessageBox and close the MessageBox afterwards, your program exits.Maybe you can replace your windows with one or two windows with a widget container like
QStackedWidget
or you replace widgets on runtime. This would reduce the amount of show / hide processes. But depends on you and your needs, what will work best for you. :)wrote on 8 Nov 2019, 14:27 last edited by hobbyProgrammer 11 Aug 2019, 14:34@Pl45m4 said in Qt app doesn't close properly (still visible in task manager):
Maybe you can replace your windows with one or two windows with a widget container like
QStackedWidget
or you replace widgets on runtime. This would reduce the amount of show / hide processes. But depends on you and your needs, what will work best for you. :)That sounds pretty good, but all the windows have different functions. The first window is to login the second is to select something and the third is a drawing app using qgraphicsview.
-
@Pl45m4 said in Qt app doesn't close properly (still visible in task manager):
Maybe you can replace your windows with one or two windows with a widget container like
QStackedWidget
or you replace widgets on runtime. This would reduce the amount of show / hide processes. But depends on you and your needs, what will work best for you. :)That sounds pretty good, but all the windows have different functions. The first window is to login the second is to select something and the third is a drawing app using qgraphicsview.
wrote on 8 Nov 2019, 14:34 last edited by Pl45m4 11 Aug 2019, 14:39@hobbyProgrammer said in Qt app doesn't close properly (still visible in task manager):
replace it with the new window
Widget, not window.
@hobbyProgrammer said in Qt app doesn't close properly (still visible in task manager):
So with QStackedWidget I don't need to hide my window
Yes, it works like a book. You can dynamically flip pages / widgets instead of showing a new window with static content.
@hobbyProgrammer said in Qt app doesn't close properly (still visible in task manager):
The first window is to login the second is to select something and the third is a drawing app using qgraphicsview
I think two windows are enough. You could use a
QDialog
to login. After successful login, you show yourQMainWindow
with yourQGraphicsView
and your "settings". Either at the same time or you put aQStackedWidget
on yourQMainWindow
and flip after you set everything up, to start drawing -
@hobbyProgrammer said in Qt app doesn't close properly (still visible in task manager):
replace it with the new window
Widget, not window.
@hobbyProgrammer said in Qt app doesn't close properly (still visible in task manager):
So with QStackedWidget I don't need to hide my window
Yes, it works like a book. You can dynamically flip pages / widgets instead of showing a new window with static content.
@hobbyProgrammer said in Qt app doesn't close properly (still visible in task manager):
The first window is to login the second is to select something and the third is a drawing app using qgraphicsview
I think two windows are enough. You could use a
QDialog
to login. After successful login, you show yourQMainWindow
with yourQGraphicsView
and your "settings". Either at the same time or you put aQStackedWidget
on yourQMainWindow
and flip after you set everything up, to start drawingwrote on 8 Nov 2019, 14:38 last edited by hobbyProgrammer 11 Aug 2019, 14:39@Pl45m4 I understand, but I would (for now) really just like to find a way to make it work with 3 screens. Unless there's an easy way to change the screens to widgets, but I don't have much experience with that.
I currently have screens with different UI's.
I use screens with menu bars etc. so how can I convert that to a widget? -
@Pl45m4 I understand, but I would (for now) really just like to find a way to make it work with 3 screens. Unless there's an easy way to change the screens to widgets, but I don't have much experience with that.
I currently have screens with different UI's.
I use screens with menu bars etc. so how can I convert that to a widget?wrote on 8 Nov 2019, 14:42 last edited by Pl45m4 11 Aug 2019, 14:44I've edited my last post. Check it out.
@hobbyProgrammer said in Qt app doesn't close properly (still visible in task manager):
I use screens with menu bars etc. so how can I convert that to a widget?
You use Menus in your
QMainWindow
, right? You can leave them as they are.
TheQStackedWidget
would only affect your MainWindowsCentralWidget
(Content ofQMainWindow
)QWidget
is the base class of nearly everything in Qt. Every widget is... well... aQWidget
(or inherits it). -
I've edited my last post. Check it out.
@hobbyProgrammer said in Qt app doesn't close properly (still visible in task manager):
I use screens with menu bars etc. so how can I convert that to a widget?
You use Menus in your
QMainWindow
, right? You can leave them as they are.
TheQStackedWidget
would only affect your MainWindowsCentralWidget
(Content ofQMainWindow
)QWidget
is the base class of nearly everything in Qt. Every widget is... well... aQWidget
(or inherits it).wrote on 8 Nov 2019, 14:54 last edited by@Pl45m4 no the menus are different for each screen. However, I think I can apply this to the first two screens. The third one is diferent...
-
@Pl45m4 no the menus are different for each screen. However, I think I can apply this to the first two screens. The third one is diferent...
wrote on 8 Nov 2019, 15:22 last edited byI think you are making it more complicated than it really is or I dont understand what you are actually doing / planing to do :)
From what I've read the last days, you are coding a more or less "simple" drawing app (with clickable and editable polygons / objects, contextMenu on rightclick and further settings in a different window.... and now with a login window at program start) Correct? -
I think you are making it more complicated than it really is or I dont understand what you are actually doing / planing to do :)
From what I've read the last days, you are coding a more or less "simple" drawing app (with clickable and editable polygons / objects, contextMenu on rightclick and further settings in a different window.... and now with a login window at program start) Correct?wrote on 11 Nov 2019, 08:14 last edited by@Pl45m4 yes that's correct
-
@Pl45m4 no the menus are different for each screen. However, I think I can apply this to the first two screens. The third one is diferent...
wrote on 11 Nov 2019, 10:36 last edited by hobbyProgrammer 11 Nov 2019, 10:36I wouldn't mind it if I had to remake the .ui file, but is there a way to keep the classes as they are?
I really don't want 1 big class for this as it would probably be 500 lines of code. I would like it to stay organized. -
wrote on 11 Nov 2019, 11:54 last edited by JonB 11 Nov 2019, 11:56
@hobbyProgrammer
Briefly, because you need this whole behaviour sorted out, as per the mess which is developing in your other thread, https://forum.qt.io/topic/108715/check-button-press-of-qmessagebox.You have two choices:
-
setQuitOnLastWindowClosed(true)
: Make sure your code always has a window open, till you/the user chooses to close it and exit the application. -
setQuitOnLastWindowClosed(false)
: If you cannot do the above, you must recognise in code when the last of your windows is closed and then exit the application explicitly.
-
-
I wouldn't mind it if I had to remake the .ui file, but is there a way to keep the classes as they are?
I really don't want 1 big class for this as it would probably be 500 lines of code. I would like it to stay organized.wrote on 11 Nov 2019, 16:12 last edited by Pl45m4 11 Nov 2019, 16:13@hobbyProgrammer said in Qt app doesn't close properly (still visible in task manager):
I really don't want 1 big class for this as it would probably be 500 lines of code
500 LOC are not that much actually :)
You need to know what you want. If you set
setQuitOnLastWindowClosed(false)
only because of your MessageBox behavior, there is something wrong / not well structured with your classes.
1/16