{"id":626,"date":"2010-05-02T23:25:33","date_gmt":"2010-05-02T22:25:33","guid":{"rendered":"http:\/\/www.thomaskeller.biz\/blog\/?p=626"},"modified":"2012-07-03T19:33:27","modified_gmt":"2012-07-03T18:33:27","slug":"quitting-a-qt-application-from-the-mac-os-x-dock","status":"publish","type":"post","link":"https:\/\/www.thomaskeller.biz\/blog\/2010\/05\/02\/quitting-a-qt-application-from-the-mac-os-x-dock\/","title":{"rendered":"Quitting a Qt application from the Mac OS X dock"},"content":{"rendered":"<p>So for some weird reason <a href=\"http:\/\/guitone.thomaskeller.biz\">my application<\/a> was not closable from the Mac OS X dock &#8211; it quit properly when you selected &#8220;Quit&#8221; from the application menu or hit the Cmd-Q shortcut &#8211; but the dock menu&#8217;s quit action was completely ignored.<\/p>\n<p>While debugging the issue I hooked into `QApplication::notify(QObject *, QEvent *)` and noted that a `QCloseEvent` was send to my application&#8230; wait, what? A `QCloseEvent`? Yes, I also thought that these kinds of events would only be send to widgets, namely, top level widgets, but I got one for my application, and Qt plainly ignored it. So I went further ahead and tried to quit the application directly when the event occured, similar to this<\/p>\n<pre lang=\"c++\">bool MyApp::event(QEvent * ev)\r\n{\r\n    bool eaten = false;\r\n    switch (ev-&gt;type())\r\n    {\r\n        \/\/ other stuff ...\r\n&#35;ifdef Q_WS_MAC:\r\n        case QEvent::Close:\r\n        {\r\n            quit();\r\n            eaten = true;\r\n            break;\r\n        }\r\n&#35;endif\r\n        default:\r\n            eaten = QCoreApplication::event(ev);\r\n            break;\r\n    }\r\n    return eaten;\r\n}\r\n<\/pre>\n<p><del datetime=\"2012-07-03T18:30:40+00:00\">but this didn&#8217;t work out so nicely: while the application quitted correctly, the `quit()` slot was apparently called twice in a row. My guess is that Qt ignores the `quitOnLastWindowClosed` property &#8211; which I&#8217;ve set to false &#8211;  and since I close all windows in the quit slot it executes quit again, or something else, so I decided to just close all open windows when the `QCloseEvent` arrived &#8211; without calling `quit()` directly, and tada, my application quitted and the slot was also only called once.<\/del> (This was a mistake on my side because I missed a break.)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>So for some weird reason my application was not closable from the Mac OS X dock &#8211; it quit properly when you selected &#8220;Quit&#8221; from the application menu or hit the Cmd-Q shortcut &#8211; but the dock menu&#8217;s quit action was completely ignored. While debugging the issue I hooked into `QApplication::notify(QObject *, QEvent *)` and &hellip; <a href=\"https:\/\/www.thomaskeller.biz\/blog\/2010\/05\/02\/quitting-a-qt-application-from-the-mac-os-x-dock\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Quitting a Qt application from the Mac OS X dock<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,5,9],"tags":[],"class_list":["post-626","post","type-post","status-publish","format-standard","hentry","category-coding","category-guitone","category-qt"],"_links":{"self":[{"href":"https:\/\/www.thomaskeller.biz\/blog\/wp-json\/wp\/v2\/posts\/626","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.thomaskeller.biz\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.thomaskeller.biz\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.thomaskeller.biz\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.thomaskeller.biz\/blog\/wp-json\/wp\/v2\/comments?post=626"}],"version-history":[{"count":6,"href":"https:\/\/www.thomaskeller.biz\/blog\/wp-json\/wp\/v2\/posts\/626\/revisions"}],"predecessor-version":[{"id":1093,"href":"https:\/\/www.thomaskeller.biz\/blog\/wp-json\/wp\/v2\/posts\/626\/revisions\/1093"}],"wp:attachment":[{"href":"https:\/\/www.thomaskeller.biz\/blog\/wp-json\/wp\/v2\/media?parent=626"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.thomaskeller.biz\/blog\/wp-json\/wp\/v2\/categories?post=626"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.thomaskeller.biz\/blog\/wp-json\/wp\/v2\/tags?post=626"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}