# Quit happening in wrong window

**URL:** <https://forum.xojo.com/t/quit-happening-in-wrong-window/44011>\
**Category:** macOS\
**Created:** [June 21, 2018, 2:52am UTC](https://forum.xojo.com/t/quit-happening-in-wrong-window/44011 "2018-06-21T02:52:36Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Arthur\_Gabhart](https://forum.xojo.com/letter_avatar_proxy/v4/letter/a/54ee81/32.png) [@Arthur\_Gabhart](https://forum.xojo.com/u/Arthur_Gabhart)\
**Post date:** [June 21, 2018, 2:52am UTC](https://forum.xojo.com/t/quit-happening-in-wrong-window/44011/1 "2018-06-21T02:52:36Z")

</div>

I am using XOJO 2018 R1.1 and Mac High Sierra.  
I have the menuitem FileQuit for the window in question Enabled = False.  
I made a mistake and hit Command - Q in the debugger and it started the Quit process.  
How can this happen?

---

<div class="post-metadata">

**Author:** ![Sam\_Rowlands](https://forum.xojo.com/user_avatar/forum.xojo.com/sam_rowlands/32/265_2.png) [@Sam\_Rowlands](https://forum.xojo.com/u/Sam_Rowlands)\
**Post date:** [June 21, 2018, 2:56am UTC](https://forum.xojo.com/t/quit-happening-in-wrong-window/44011/2 "2018-06-21T02:56:32Z")

</div>

The correct way to do it is to “return True” from the Cancel Close event of the window until you’re ready to let the window go.

---

<div class="post-metadata">

**Author:** ![Arthur\_Gabhart](https://forum.xojo.com/letter_avatar_proxy/v4/letter/a/54ee81/32.png) [@Arthur\_Gabhart](https://forum.xojo.com/u/Arthur_Gabhart)\
**Post date:** [June 21, 2018, 3:17am UTC](https://forum.xojo.com/t/quit-happening-in-wrong-window/44011/3 "2018-06-21T03:17:20Z")

</div>

Thanks. Consider that done. My confusion is I don’t have that menuitem in the Window So Command - Q is not valid.  
It is in certain windows, like my main window, but not this one.  
It might also be closing because I don’t have the main window open, but that should be re-opening since this one is closing.

But still I should be getting a beep for invalid selection.

---

<div class="post-metadata">

**Author:** ![Greg\_O\_Lone](https://forum.xojo.com/user_avatar/forum.xojo.com/greg_o_lone/32/49_2.png) [@Greg\_O\_Lone](https://forum.xojo.com/u/Greg_O_Lone)\
**Post date:** [June 21, 2018, 3:26am UTC](https://forum.xojo.com/t/quit-happening-in-wrong-window/44011/4 "2018-06-21T03:26:54Z")

</div>

Cmd-Q in the debugger first stops the debugging process which terminates your app, whatever state its in.

---

<div class="post-metadata">

**Author:** ![Roger\_Clary](https://forum.xojo.com/letter_avatar_proxy/v4/letter/r/eada6e/32.png) [@Roger\_Clary](https://forum.xojo.com/u/Roger_Clary)\
**Post date:** [June 21, 2018, 5:16am UTC](https://forum.xojo.com/t/quit-happening-in-wrong-window/44011/5 "2018-06-21T05:16:58Z")

</div>

What Greg has suggested is probably the solution to your immediate problem, but this thread may be of interest to you in a discussion of FileQuit.  
[https://forum.xojo.com/41867-can-t-disable-filequit](https://forum.xojo.com/41867-can-t-disable-filequit)

---

<div class="post-metadata">

**Author:** ![Arthur\_Gabhart](https://forum.xojo.com/letter_avatar_proxy/v4/letter/a/54ee81/32.png) [@Arthur\_Gabhart](https://forum.xojo.com/u/Arthur_Gabhart)\
**Post date:** [June 21, 2018, 12:40pm UTC](https://forum.xojo.com/t/quit-happening-in-wrong-window/44011/6 "2018-06-21T12:40:42Z")

</div>

I tried searching for quit Only and the post didn’t show. Grumble.  
Thanks for verifying this is supposed to happen.  
I read the post and it almost answers my problem.

I had removed appQuitting = false from this window’s cancelClose because it didn’t stop the Quit.  
I also put it back in and it didn’t stop the Quit.  
So, if appQuitting = False in the cancelClose doesn’t work, what would?

[quote]it would be much more polite to put a dialog in cancelclose telling the user that they must close the window first. If you do this

```auto
Return AppQuitting
```

---

<div class="post-metadata">

**Author:** ![Roger\_Clary](https://forum.xojo.com/letter_avatar_proxy/v4/letter/r/eada6e/32.png) [@Roger\_Clary](https://forum.xojo.com/u/Roger_Clary)\
**Post date:** [June 21, 2018, 12:54pm UTC](https://forum.xojo.com/t/quit-happening-in-wrong-window/44011/7 "2018-06-21T12:54:54Z")

</div>

You Return True in the cancelClose event to stop the window from closing or in the app.cancelClose event to stop the app from quitting. You must notify the user as to why you canceled

---

<div class="post-metadata">

**Author:** ![Arthur\_Gabhart](https://forum.xojo.com/letter_avatar_proxy/v4/letter/a/54ee81/32.png) [@Arthur\_Gabhart](https://forum.xojo.com/u/Arthur_Gabhart)\
**Post date:** [June 21, 2018, 1:42pm UTC](https://forum.xojo.com/t/quit-happening-in-wrong-window/44011/8 "2018-06-21T13:42:18Z")

</div>

Figured out my bigger problem.  
I have the main window that opens during the other window’s close event.  
That is bad for Mac since Quit is already happening and will continue. Bad programming in retrospect.  
Therefore, I add the FileQuit menu item to each other window with a dialogue.

Edit:  
On further testing. The reason this is now happening is I now have only that second window open and had closed the main window.  
In other words, in the main window, in the menuitem that opened the second window, I had self.close followed by otherWind.open  
If remove that self.close then FileQuit doesn’t happen inappropriately,  
but I need to add the menuHandler and the cancelClose handling in case that window is the only window open.

Further Edit:  
The menuHandler for FileQuit is in each window’s since if it’s in App, it overrides any window’s menuHandler.  
I also have code in EnableMenuItems

```auto
If WindowCount > 1 Then FileQuit.Enabled = False
```

---

<div class="post-metadata">

**Author:** ![Carlo\_Rubini](https://forum.xojo.com/letter_avatar_proxy/v4/letter/c/94ad74/32.png) [@Carlo\_Rubini](https://forum.xojo.com/u/Carlo_Rubini)\
**Post date:** [June 21, 2018, 11:25pm UTC](https://forum.xojo.com/t/quit-happening-in-wrong-window/44011/9 "2018-06-21T23:25:06Z")

</div>

> [@](#):
>
> I had self.close followed by otherWind.open

Is there any reason for you to close the mainwindow? Would not self.hide work better? Then, I think, all those quit things, if they are really necessary, may start working properly, and the main window would be the last to get closed.

---

<div class="post-metadata">

**Author:** ![Arthur\_Gabhart](https://forum.xojo.com/letter_avatar_proxy/v4/letter/a/54ee81/32.png) [@Arthur\_Gabhart](https://forum.xojo.com/u/Arthur_Gabhart)\
**Post date:** [June 21, 2018, 11:41pm UTC](https://forum.xojo.com/t/quit-happening-in-wrong-window/44011/10 "2018-06-21T23:41:08Z")

</div>

I had thought it would resolve its or my problem of updating its data and therefore it would un-hide. It caused more problems, so I went back to it being open.  
The reason I chose to close it is its activate would cause it to reappear.  
Thanks. I had forgotten about that problem.

---

<div class="post-metadata">

**Author:** ![system](https://forum.xojo.com/uploads/default/original/1X/455b4dcc0e61630e9f81940004ddffa49c432a46.png) [@system](https://forum.xojo.com/u/system)\
**Post date:** [October 29, 2020, 7:15pm UTC](https://forum.xojo.com/t/quit-happening-in-wrong-window/44011/11 "2020-10-29T19:15:23Z")

</div>


