QFileOpenEvent
-
Hi,
I am implementing responding to QFileOpenEvent to support MacOS Finder actions (double clicking on documents, dropping files on Dock, open with... etc.). I am pretty much following the exact example here: https://doc.qt.io/qt-6/qfileopenevent.html#macos-example and instancing the derived application class in my app.
My application is also able to respond to command line parameters to open files on other platforms and set various debugging actions.
The weird behavior I am seeing is that when I launch my application with some debugging command line parameters on the Mac, the FileOpenEvent gets called several times for some of the file system paths that were passed in the command line options.
My expectation was that would only get events from the system Finder events.
Is there some kind of automatic processing of command line parameters taking place and generating FileOpen events?
A quick look at the source code did not turn any. The main uses of the class I found were QGuiApplicationPrivate::processFileOpenEvent which is in turn called by QGuiApplicationPrivate::processWindowSystemEvent
Does anyone have any idea what may be going on?
-
Hi,
I am implementing responding to QFileOpenEvent to support MacOS Finder actions (double clicking on documents, dropping files on Dock, open with... etc.). I am pretty much following the exact example here: https://doc.qt.io/qt-6/qfileopenevent.html#macos-example and instancing the derived application class in my app.
My application is also able to respond to command line parameters to open files on other platforms and set various debugging actions.
The weird behavior I am seeing is that when I launch my application with some debugging command line parameters on the Mac, the FileOpenEvent gets called several times for some of the file system paths that were passed in the command line options.
My expectation was that would only get events from the system Finder events.
Is there some kind of automatic processing of command line parameters taking place and generating FileOpen events?
A quick look at the source code did not turn any. The main uses of the class I found were QGuiApplicationPrivate::processFileOpenEvent which is in turn called by QGuiApplicationPrivate::processWindowSystemEvent
Does anyone have any idea what may be going on?
Hi and welcome to devnet,
Would it be possible to have a minimal compilable example that shows this behaviour ?
Which version of macOS are you running ?
-
Running on macOS Monterey 12.3
Unfortunately nothing I am able to share here. But this should be reproducible with a minimal example based on https://doc.qt.io/qt-6/qfileopenevent.html#macos-example.
And subsequently calling the application inside the bundle from the console:
bundle.app/Contents/MacOS/bundle TestA TestB
the example should output Open file TestA and Open file TestB to the console.
In further investigation, I omitted passing the argc/argv values to Qt via QGuiApplication and the behavior continued which makes me believe this is something MacOS might be doing and not Qt.
-
This seems to mention a similar issue documenting behavior from NSApplication on MacOS:
https://lists.apple.com/archives/cocoa-dev/2009/May/msg00480.html -
My solution was to create a list of all the command line arguments not starting with '-' or directly following one starting with '-' in the derived Application class constructor.
In the FileOpenEvent handler, the filename is checked against that list, and if found the event is ignored and the filename is removed from the list, otherwise the event is handled normally and tries to open a file.
-