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. Using file association on macOS
Forum Update on Monday, May 27th 2025

Using file association on macOS

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 38 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.
  • PerdrixP Offline
    PerdrixP Offline
    Perdrix
    wrote last edited by
    #1

    My application registers a type with UTI, and the application is now opened when the file with the correct extension is double-clicked in Finder, but it doesn't actually open the file? I expected the application to be invoked like (e.g.):

    /Applications/DeepSkyStacker.app/Contents/MacOS/DeepSkyStacker Documents/Astrophotography/NGC\ 457\ Owl\ Cluster/NGC457.dssfilelist
    

    which when typed from the command line opened the file as expected. But clearly that isn't how the application was invoked by the system when I double-clicked the file in Finder.

    What am I not understanding here - I'm guessing there's something "special" I need to do on macOS to handle this properly?

    Thanks
    David

    1 Reply Last reply
    0
    • J.HilkJ Offline
      J.HilkJ Offline
      J.Hilk
      Moderators
      wrote last edited by
      #2

      On macOS, when a file is double-clicked in Finder, the system launches your application. The file is passed via macOS's Apple Events mechanism.

      IIRC Qt provides a means to handle this.
      You'll need an eventFilter on your QApplication, that is listening to Event::FileOpen events than you can work from there.

      Something like this:

          bool event(QEvent *event) override {
              if (event->type() == QEvent::FileOpen) {
                  auto *fileOpenEvent = static_cast<QFileOpenEvent *>(event);
                  QString filePath = fileOpenEvent->file();
                  qDebug() << "File to open:" << filePath;
      
                  // Store or open the file as needed
                  // e.g. emit signal or call method to process the file
      
                  return true;
              }
              return QApplication::event(event);
          }
      
      

      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      1 Reply Last reply
      5
      • PerdrixP Perdrix has marked this topic as solved
      • PerdrixP Offline
        PerdrixP Offline
        Perdrix
        wrote last edited by
        #3

        Thank you lots

        David

        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