Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Clicking the dock icon to show the app on Mac
Forum Update on Monday, May 27th 2025

Clicking the dock icon to show the app on Mac

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 4.7k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    Priyanka
    wrote on 30 Aug 2010, 22:22 last edited by
    #1

    Hello,

    I'm building a desktop application using Qt 4.6.2 for both Mac and Windows.
    I wanted to implement some Mac specific behavior:
    When you click the Close button in the main application window, the application window should close but it shouldn't quit.
    -> I've got this part working
    When you click on the application dock icon, the application window should be shown and brought to the front.
    -> I'm able to get this to work as long as some other application is the active application. If my application is still the active app, then clicking on the dock icon has no effect.

    Can anyone help me with this problem?

    Thanks,
    Priyanka

    1 Reply Last reply
    0
    • V Offline
      V Offline
      vemod
      wrote on 12 Sept 2011, 10:56 last edited by
      #2

      I know it is an old thread but here is a workaround that seems to be OK:

      @
      void MainWindow::closeEvent(QCloseEvent *event)
      {
      #ifdef MACOSX_CORE
      if (event->spontaneous())
      {
      QStringList args;
      args << "-e";
      args << "tell application "System Events"";
      args << "-e";
      args << "set visible of process ""+QFileInfo(QApplication::applicationFilePath()).baseName()+"" to false";
      args << "-e";
      args << "end tell";
      QProcess::execute("osascript", args);
      event->ignore();
      return;
      }
      #endif

      //Do quit stuff
      }
      @

      I would have guessed spontaneous() should work the other way around...

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved