Using file association on macOS
-
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 -
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); }
-
P Perdrix has marked this topic as solved