Who closes application on Escape?
-
Hi,
I accidently hit Escape and the application was closed as fast as possible.
I was astonished, as I did not code that feature.And as I don't want that feature, I tried to find the source of it.
AddingkeyPressEvent
to MainWindow did not work.
So I started Application in debugger and put a breakpoint atQApplication::event()
but debugger did not stop at Escape.According Qt documentation of
QKeySequence
there's no standard shortcut bound to Escape-key beside QKeySequence::Cancel but I could not find the source, where Escape should close the application.Debugger just says that application has finished with exit-code 0.
How can I find out, who is responsible for closing application?
-
Hi,
I accidently hit Escape and the application was closed as fast as possible.
I was astonished, as I did not code that feature.And as I don't want that feature, I tried to find the source of it.
AddingkeyPressEvent
to MainWindow did not work.
So I started Application in debugger and put a breakpoint atQApplication::event()
but debugger did not stop at Escape.According Qt documentation of
QKeySequence
there's no standard shortcut bound to Escape-key beside QKeySequence::Cancel but I could not find the source, where Escape should close the application.Debugger just says that application has finished with exit-code 0.
How can I find out, who is responsible for closing application?
-
Hi,
I accidently hit Escape and the application was closed as fast as possible.
I was astonished, as I did not code that feature.And as I don't want that feature, I tried to find the source of it.
AddingkeyPressEvent
to MainWindow did not work.
So I started Application in debugger and put a breakpoint atQApplication::event()
but debugger did not stop at Escape.According Qt documentation of
QKeySequence
there's no standard shortcut bound to Escape-key beside QKeySequence::Cancel but I could not find the source, where Escape should close the application.Debugger just says that application has finished with exit-code 0.
How can I find out, who is responsible for closing application?
@django-Reinhard
Every
QDialog
subclass will receive areject
onESC
-key and close afterwards (or whatever you do when it got rejected).Edit:
And even if you have a
QMainWindow
but it's hidden at this moment, the dialog will receive areject
and yourQApp
will exit properly.Damn @J-Hilk, I was editing my post, when you wrote the same I was about to write :)
-
to add to @Pl45m4
if you have a QDialog open, and all other widgets are hidden, and you press esc, than due to
https://doc.qt.io/qt-5/qguiapplication.html#quitOnLastWindowClosed-prop property, that is by default set to true, your whole program should close
@Pl45m4 great minds think alike 😎
-
I'm sure the OP would have said if he had a
QDialog
open and was pressing the Escape key there.....@JonB said in Who closes application on Escape?:
I'm sure the OP would have said if he had a QDialog open and was pressing the Escape key there.....
There is no other possibility than this... A
QMainWindow
never closes onESC
by default unless you modify key- and closeEvents.Edit:
It's more likely our 2nd guess... Maybe theQMainWindow
was hidden and some dialog the last visible widget. -
@JonB said in Who closes application on Escape?:
I'm sure the OP would have said if he had a QDialog open and was pressing the Escape key there.....
There is no other possibility than this... A
QMainWindow
never closes onESC
by default unless you modify key- and closeEvents.Edit:
It's more likely our 2nd guess... Maybe theQMainWindow
was hidden and some dialog the last visible widget. -
I'm sure the OP would have said if he had a
QDialog
open and was pressing the Escape key there.....@JonB said in Who closes application on Escape?:
I'm sure the OP would have said if he had a
QDialog
open and was pressing the Escape key there.....your faith in humanity is adorable 😘
-
@Pl45m4
I agree, which is what I said. Just I'm sure the OP would have mentioned this vital piece of information if he were using a dialog, another window, or the main window was closed/hidden.... :)@JonB said in Who closes application on Escape?:
Just I'm sure the OP would have mentioned this vital piece of information if he were using a dialog
Haha. What I've learned from almost 3 years of being active here: Never trust OP's description of any issue :))
-
Thank you all for your attention!
... and no! I'm not using or talking about any dialog.
I'm talking about QMainWindow.
A dialog closing on escape wouldn't have surprised me at all.Just to be detailed and clear:
I have only QMainWindow open. This window is enriched by lots of dockables and several widgets have keyPressed overridden.When I close the application by menu action or by titlebar button, a messagebox pops up to ask, whether I wonna close the app.
When I hit escape, the application shuts down that fast as if I would throw an exception. That has surprised me.
If I debug the app and an exception is thrown, the debugger tells me, that it had received a kill signal and I see the stack, so I can investigate what happened.
In this case, the debugger says nothing and there's no stacktrace.The app has just terminated as intended.
I added a debug message to main after application::exec and that message is printed. So Escape terminates the eventloop and the main function ends normally.
-
Thank you all for your attention!
... and no! I'm not using or talking about any dialog.
I'm talking about QMainWindow.
A dialog closing on escape wouldn't have surprised me at all.Just to be detailed and clear:
I have only QMainWindow open. This window is enriched by lots of dockables and several widgets have keyPressed overridden.When I close the application by menu action or by titlebar button, a messagebox pops up to ask, whether I wonna close the app.
When I hit escape, the application shuts down that fast as if I would throw an exception. That has surprised me.
If I debug the app and an exception is thrown, the debugger tells me, that it had received a kill signal and I see the stack, so I can investigate what happened.
In this case, the debugger says nothing and there's no stacktrace.The app has just terminated as intended.
I added a debug message to main after application::exec and that message is printed. So Escape terminates the eventloop and the main function ends normally.
@django-Reinhard said in Who closes application on Escape?:
and several widgets have keyPressed overridden.
I can only think that somehow this is relevant. Remove all of this, or better still create a standalone 4-line program which just opens a
QMainWindow
and verify that Escape does not end the application. Then work back/forward from there, because the way you describe it sounds like the Qt app is indeed exiting "cleanly" if it returns fromQApplication::exec()
. -
Hi,
I accidently hit Escape and the application was closed as fast as possible.
I was astonished, as I did not code that feature.And as I don't want that feature, I tried to find the source of it.
AddingkeyPressEvent
to MainWindow did not work.
So I started Application in debugger and put a breakpoint atQApplication::event()
but debugger did not stop at Escape.According Qt documentation of
QKeySequence
there's no standard shortcut bound to Escape-key beside QKeySequence::Cancel but I could not find the source, where Escape should close the application.Debugger just says that application has finished with exit-code 0.
How can I find out, who is responsible for closing application?
@django-Reinhard said in Who closes application on Escape?:
Debugger just says that application has finished with exit-code 0.
A crash would not result in exit code 0.
Probably there is something wrong with your keyHandler -
@django-Reinhard said in Who closes application on Escape?:
and several widgets have keyPressed overridden.
I can only think that somehow this is relevant. Remove all of this, or better still create a standalone 4-line program which just opens a
QMainWindow
and verify that Escape does not end the application. Then work back/forward from there, because the way you describe it sounds like the Qt app is indeed exiting "cleanly" if it returns fromQApplication::exec()
.Hi,
thanks to your numerous "Qt won't do that" it was easy to me to find the culprit.
@JonB said in Who closes application on Escape?:
I can only think that somehow this is relevant.
You're right.
I use an opencascade widget, which I didn't spend much time for investigation. I just used it as is. And that widget killed the app at Escape key press.Anyway - with this lesson I learned a lot about event-handling in Qt.