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. QFileOpenEvent
Forum Updated to NodeBB v4.3 + New Features

QFileOpenEvent

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 2 Posters 481 Views 1 Watching
  • 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.
  • S Offline
    S Offline
    SebChevrel
    wrote on last edited by
    #1

    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?

    SGaistS 1 Reply Last reply
    0
    • S SebChevrel

      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?

      SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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 ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • S Offline
        S Offline
        SebChevrel
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SebChevrel
          wrote on last edited by
          #4

          This seems to mention a similar issue documenting behavior from NSApplication on MacOS:
          https://lists.apple.com/archives/cocoa-dev/2009/May/msg00480.html

          1 Reply Last reply
          0
          • S Offline
            S Offline
            SebChevrel
            wrote on last edited by
            #5

            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.

            1 Reply Last reply
            0
            • S SebChevrel has marked this topic as solved on

            • Login

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