PDA

View Full Version : File association in mac os x



volcano
14th July 2015, 09:08
Hi All,

Can you detail me the steps for file association for deploying a Qt app on mac os x?

Regards,
volcano

jefftee
14th July 2015, 10:09
I'm not aware of a Qt class that provides this functionality. To my knowledge this is done in an OS specific method. Start with the link below for the section on OSX and also google for more information:

https://en.wikipedia.org/wiki/File_association

uliwitness
24th May 2017, 17:51
I poked around in the sources a bit, and here's what I found:

1. Given macOS looks for file associations in the application's Info.plist, you'll have to set up your app's with the proper CFBundleDocumentTypes keys. You also have to set your QMAKE_INFO_PLIST key to point to that Info.plist file
2. Qt's Mac code has a QCocoaIntegration object, which creates a QCocoaApplicationDelegate and provides that to macOS as the application delegate.
3. If your cocoa application already has a delegate set, QCocoaIntegration will replace it with its delegate and install it in the QCocoaApplicationDelegate as the "reflectionDelegate", to which it forwards, among others, the -application:openFiles: delegate method.
4. So, to handle file open requests, create an Objective-C NSObject subclass that conforms to the NSApplicationDelegate protocol and implements -application:openFiles: just like any other Mac application would do, and install it into [NSApplication sharedApplication] as the delegate.
5. From that object, call out to your Qt code and do whatever you want to do in response to a file being opened.

Note: I've only read the Qt sources so far, I have yet to actually try this out. You may have to make sure you get your delegate in before QCocoaIntegration installs its delegate.