title: Qt on Mac OS - Detecting a click on the dock menu
body: <p>I am dropping the system tray icon for the Mac OS version of my application. However there's one small problem: when the user closes the main window the application is supposed to continue to run on the background and the main window should become visible again if the user clicks the dock icon. So far I have found no way of intercepting this click on the icon. </p>
  
  <p>Is there any way to accomplish this with Qt? If not, how should I proceed with the native API to implement this behavior?</p>
  
  <p>I have tried to create a custom application class that implement QApplication so that I can re-implement the macEventFilter but the documentation on this function is scarce.</p>
  
  <p>application.h:</p>
  
  <pre><code>#ifndef APPLICATION_H
  #define APPLICATION_H
  
  #include &lt;QApplication&gt;
  
  class QWidget;
  
  class Application : public QApplication
  {
      Q_OBJECT
  
  public:
  
      Application(int, char*[]);
      void setMainWidget(QWidget*);
      bool macEventFilter(EventHandlerCallRef, EventRef);
  
  private:
      QWidget *mainWidget;
  };
  
  #endif // APPLICATION_H
  </code></pre>
  
  <p>application.cpp:</p>
  
  <pre><code>#include &lt;Application.h&gt;
  #include &lt;QWidget&gt;
  
  Application::Application(int argc, char *argv[])
      : QApplication(argc, argv)
  {
  }
  
  void Application::setMainWidget(QWidget *mainWidget)
  {
      this-&gt;mainWidget = mainWidget;
  }
  
  bool Application::macEventFilter(EventHandlerCallRef, EventRef)
  {
      mainWidget-&gt;show();
      return false;
  }
  </code></pre>
  
  <p>main.cpp:</p>
  
  <pre><code>    #include &lt;QtCore&gt;
      #include &lt;Application.h&gt;
      #include "mainwidget.h"
  
      int main(int argc, char *argv[]) {
          Application a(argc, argv);
  
          MainWidget mainWidget;
  
      #ifdef Q_WS_MAC
  
          a.setWindowIcon(QIcon(":/resource/army-officer-icon.png"));
  
      #endif
  
          a.setMainWidget((QWidget*)&amp;mainWidget);
  
          mainWidget.show();
  
          return a.exec(); 
      }
  </code></pre>