How to close a application on macos

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Jens
Posts: 14
Joined: Sun Nov 11, 2007 5:44 pm
Location: Germany

How to close a application on macos

Post by Jens »

hello community,

I was playing around with Irrlicht 1.4 since it got ported to mac os (again).
I tried the first example "Hello World" and everything was fine until I wanted to close the application ^^

People using MacOS know that closing the window does not close your application. Mostly you have to use the "cmd + q" shortcut or close it by using the menubar.

So my question is if there is a code snippet which could teach me how to implent a eventhandler or something like that to close my application by pressing "cmd + q".

I hope you are not to bored by this question but as you can see I am a noob when it comes to developing on macos cause my first mac arrived in mid-november :)

I tried to use the "interface designer/builder" but I was not able to use this in my application because I dont know how :(
The documentation at the "apple developer connection" did not helped me :/

greets jens
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

well, it seems you're also a noob with search functions.... :lol:
you should always do a search (or two) before asking, it usually saves a lot of time and helps not flooting the forum with the same question again and again... ;)


you should create an event receiver and define a key (usually Escape) for closing the program...

ok, I did the search for you and this are the most relevant threads for this:
http://irrlicht.sourceforge.net/phpBB2/ ... php?t=3893
http://irrlicht.sourceforge.net/phpBB2/ ... php?t=2586
http://irrlicht.sourceforge.net/phpBB2/ ... php?t=7468
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
Jens
Posts: 14
Joined: Sun Nov 11, 2007 5:44 pm
Location: Germany

Post by Jens »

@acki

thanks for your help and search but this does not help me because this is a mac-related question. You dont have a mac, do you?
On MacOS the application is divided in a menu which is always on the top of the screen and (most times) a window where you make all your actions.
even if you close the window the application itself is still running.

I am searching for a snippet or tutorial which shows how to close the application and not just the window.

the threads you posted are more windows specific ;)
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

Jens wrote:the threads you posted are more windows specific ;)
no, they are Irrlicht specific and should work on all systems (win, linux and propably mac)... ;)

well, you're right I'm using Windoofs, so I can't check this... :oops:
but shouldn't it be that if the main function exits with return 0; (or maybe with exit(0);) that the program ends ???

but in either case you'll have to create an event receiver and catch a key for closing the program, like in the threads I mentioned... ;)
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
Jens
Posts: 14
Joined: Sun Nov 11, 2007 5:44 pm
Location: Germany

Post by Jens »

@acki

I already tried exit(0) and stuff which I used on windows xD
but this doesnt seem to work well on macos xD

but thanks for your help anyway ;)
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

The typical system close codes should work by closing the application by sending a system event which should be handled in the device. This is how the Windows close event and the X11 close event are handled. If the OSX device does not provide for the typical system close it has to be added. But I also don't know OSX, so I cannot help any further.
bigzpanda
Posts: 8
Joined: Fri Dec 21, 2007 11:24 am

Post by bigzpanda »

I do this in my events class:

Code: Select all

virtual bool OnEvent(SEvent event)
	{
		if (event.EventType == EET_KEY_INPUT_EVENT  && event.KeyInput.PressedDown)
		{
  			switch(event.KeyInput.Key)
			{
			case KEY_ESCAPE:
			quit=1;
			break;
			}
  		
		return true;
	}
	}
And this in my render loop:

Code: Select all

while (device->run() && quit==0)
    {
	}
    device->drop ();
If you want to quit with command+Q, you can too add Mainmenu.nib to your Xcode project(the file is in the "source" directory)
Jens
Posts: 14
Joined: Sun Nov 11, 2007 5:44 pm
Location: Germany

Post by Jens »

thank you bigzpanda.
i'll test your code as soon as I am back at my mac ^^
Post Reply