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. How do I know if I won't receive a FileOpen event?

How do I know if I won't receive a FileOpen event?

Scheduled Pinned Locked Moved Solved General and Desktop
13 Posts 4 Posters 1.3k Views 2 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.
  • K Offline
    K Offline
    Kerndog73
    wrote on last edited by Kerndog73
    #1

    I have an application that edits files. When the user double clicks on a file, my application is launched and the FileOpen event is received. When my application is launched directly by the user, a dialog window for creating a new file is shown.

    The problem that I'm having is that I don't know if I'm not going to receive the FileOpen event. When my application launches, I show the file creation dialog window. Then when I receive the FileOpen event, I close the dialog window and open the file. The result is that the dialog window flashes on the screen for a moment.

    FileOpen is received after ApplicationStateChange which means I can't wait until ApplicationStateChange and then show the dialog only if FileOpen wasn't received.

    Should I set a timer to show the dialog after 500ms if FileOpen wasn't received? That seems kind of hacky to me. I don't really want to sacrifice launch time to get this to work. Is there another way of getting this information other than through events?

    1 Reply Last reply
    0
    • K Offline
      K Offline
      Kerndog73
      wrote on last edited by
      #2

      I've just discovered some shocking news. The FileOpen event is only supported by macOS.

      Seriously? Why? I'm genuinely shocked.

      jsulmJ 1 Reply Last reply
      0
      • K Kerndog73

        I've just discovered some shocking news. The FileOpen event is only supported by macOS.

        Seriously? Why? I'm genuinely shocked.

        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #3

        @Kerndog73 said in How do I know if I won't receive a FileOpen event?:

        Why?

        That you should ask Qt developers on their mailing list

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        K 1 Reply Last reply
        0
        • jsulmJ jsulm

          @Kerndog73 said in How do I know if I won't receive a FileOpen event?:

          Why?

          That you should ask Qt developers on their mailing list

          K Offline
          K Offline
          Kerndog73
          wrote on last edited by
          #4

          @jsulm Nah, I won't bother them with my nonsense.

          jsulmJ 1 Reply Last reply
          0
          • K Kerndog73

            @jsulm Nah, I won't bother them with my nonsense.

            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @Kerndog73 Well, I don't know why it is only supported on MacOS. You can take a look at the source code, maybe you will find out why.

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0
            • K Offline
              K Offline
              Kerndog73
              wrote on last edited by
              #6

              My solution for the moment is to set a timer for 100ms. I consistently have about 20-30ms to spare so this seems to be a good time. The big problem with this is that I'm setting a timer for 100ms! This just feels so wrong. There has to be a better way.

              This is just as bad as those ancient video games that depend on the clock speed of the machine they're running on.

              jsulmJ 1 Reply Last reply
              0
              • K Kerndog73

                My solution for the moment is to set a timer for 100ms. I consistently have about 20-30ms to spare so this seems to be a good time. The big problem with this is that I'm setting a timer for 100ms! This just feels so wrong. There has to be a better way.

                This is just as bad as those ancient video games that depend on the clock speed of the machine they're running on.

                jsulmJ Offline
                jsulmJ Offline
                jsulm
                Lifetime Qt Champion
                wrote on last edited by
                #7

                @Kerndog73 I'm not sure, but don't you get the file name user double clicked, as a parameter to your app (I mean argc/argv)? If this is the case you don't need that event and can easily check whether you should show file open dialog or not.

                https://forum.qt.io/topic/113070/qt-code-of-conduct

                K 1 Reply Last reply
                0
                • jsulmJ jsulm

                  @Kerndog73 I'm not sure, but don't you get the file name user double clicked, as a parameter to your app (I mean argc/argv)? If this is the case you don't need that event and can easily check whether you should show file open dialog or not.

                  K Offline
                  K Offline
                  Kerndog73
                  wrote on last edited by
                  #8

                  @jsulm That doesn't seem to be the case, unfortunately. The only command line argument I get is -psn_0_29527079. I've got no idea what that means!

                  1 Reply Last reply
                  0
                  • SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    Hi,

                    There's nothing specially shocking, it just means that there was no other OS providing a similar event as macOS does.

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

                    K 1 Reply Last reply
                    2
                    • SGaistS SGaist

                      Hi,

                      There's nothing specially shocking, it just means that there was no other OS providing a similar event as macOS does.

                      K Offline
                      K Offline
                      Kerndog73
                      wrote on last edited by
                      #10

                      @SGaist But Windows supports this feature, doesn't it? I mean, when you double click on a .docx file, MS Word is asked to open it, right?

                      1 Reply Last reply
                      0
                      • SGaistS Offline
                        SGaistS Offline
                        SGaist
                        Lifetime Qt Champion
                        wrote on last edited by
                        #11

                        I don't know how that part is currently done on Windows. It could be just that a parameter is passed to the executable or something completely different.

                        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
                        1
                        • W Offline
                          W Offline
                          wrosecrans
                          wrote on last edited by
                          #12

                          I don't know OS-X guts well enough to give a precise answer, but in the underlying Cocoa API's, it's possible to decide you aren't getting on initial openFile event as soon as you get the applicationDidFinishLaunching event. I dunno if that's actually plumbed through to Qt in any obvious way, or if it's easy to check by dropping to some native code in a way that doesn't break Qt.

                          https://developer.apple.com/documentation/appkit/nsapplicationdelegate/1428612-application?language=objc

                          Maybe it's enough to set a 0ms timer rather than 100ms? I don't have a Mac to test with, but perhaps the timeout of a 0ms timer won't actually be serviced until after the application has "finished launching" ?

                          K 1 Reply Last reply
                          2
                          • W wrosecrans

                            I don't know OS-X guts well enough to give a precise answer, but in the underlying Cocoa API's, it's possible to decide you aren't getting on initial openFile event as soon as you get the applicationDidFinishLaunching event. I dunno if that's actually plumbed through to Qt in any obvious way, or if it's easy to check by dropping to some native code in a way that doesn't break Qt.

                            https://developer.apple.com/documentation/appkit/nsapplicationdelegate/1428612-application?language=objc

                            Maybe it's enough to set a 0ms timer rather than 100ms? I don't have a Mac to test with, but perhaps the timeout of a 0ms timer won't actually be serviced until after the application has "finished launching" ?

                            K Offline
                            K Offline
                            Kerndog73
                            wrote on last edited by
                            #13

                            @wrosecrans A 0ms timer seems to have solved the problem! The timer only times out after the application is fully initialised. This kind of makes sense because a 0ms timer is the “right solution” to some other problems too.

                            1 Reply Last reply
                            1

                            • Login

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