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. Command line arguments multiple file paths

Command line arguments multiple file paths

Scheduled Pinned Locked Moved Solved General and Desktop
9 Posts 5 Posters 2.6k Views
  • 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.
  • Joel BodenmannJ Offline
    Joel BodenmannJ Offline
    Joel Bodenmann
    wrote on last edited by Joel Bodenmann
    #1

    I wrote a Qt application that is able to handle plain text files. I told my operating system (Windows) to use that application to open that file type (extension) if I double-click it in the file explorer. That works fairly well: When I double-click a file with the registered extension it opens my Qt program and passes the file path as a command line parameter.
    From other Windows software I'm used to the fact that when I select multiple files in the file explorer and hit enter, it will again launch the default program for that file extension and pass all selected files as arguments so that at the end there's one instance of that program showing/loading all the selected files.
    However, with my application it's different. When I select multiple files in the file explorer and hit the enter key, it spawns one program instance per selected file. Each program instance gets one file path passed as an argument.

    What exactly is the magic behind all of this? What do I have to do to make windows pass all selected files as command line parameters to one instance of my program?
    I have no idea what causes different behavior here as I expect this to be handled on the operating system level. I don't even know what to google for.
    I am thankful for any kind of advice / hint / remark / solution.

    In case of this is relevant: I'm using the Qt installer framework to install my application on the target computer.

    Industrial process automation software: https://simulton.com
    Embedded Graphics & GUI library: https://ugfx.io

    raven-worxR 1 Reply Last reply
    0
    • Joel BodenmannJ Joel Bodenmann

      I wrote a Qt application that is able to handle plain text files. I told my operating system (Windows) to use that application to open that file type (extension) if I double-click it in the file explorer. That works fairly well: When I double-click a file with the registered extension it opens my Qt program and passes the file path as a command line parameter.
      From other Windows software I'm used to the fact that when I select multiple files in the file explorer and hit enter, it will again launch the default program for that file extension and pass all selected files as arguments so that at the end there's one instance of that program showing/loading all the selected files.
      However, with my application it's different. When I select multiple files in the file explorer and hit the enter key, it spawns one program instance per selected file. Each program instance gets one file path passed as an argument.

      What exactly is the magic behind all of this? What do I have to do to make windows pass all selected files as command line parameters to one instance of my program?
      I have no idea what causes different behavior here as I expect this to be handled on the operating system level. I don't even know what to google for.
      I am thankful for any kind of advice / hint / remark / solution.

      In case of this is relevant: I'm using the Qt installer framework to install my application on the target computer.

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      @Joel-Bodenmann
      AFAIK it's only possible to open one instance per file.
      But there are techniques (DDE for example) to overcome this limitation.

      Or the Qt/x-Platform approach: QtSingleApplication from the QtSolutions repo
      Once you've integrated QtSingleApplication into your application all instances launched will communicate with the first launched instance and should close itself after telling the first instance to open the received file.

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      Joel BodenmannJ 1 Reply Last reply
      2
      • mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by mrjj
        #3

        Hi
        Notepad does the same. ( for some ini file)

        I think the apps that dont,
        handles multiple instances them self.
        So if started with a file and already running, give it to other instance.

        (edit: raven-worx was faster :)

        1 Reply Last reply
        0
        • raven-worxR raven-worx

          @Joel-Bodenmann
          AFAIK it's only possible to open one instance per file.
          But there are techniques (DDE for example) to overcome this limitation.

          Or the Qt/x-Platform approach: QtSingleApplication from the QtSolutions repo
          Once you've integrated QtSingleApplication into your application all instances launched will communicate with the first launched instance and should close itself after telling the first instance to open the received file.

          Joel BodenmannJ Offline
          Joel BodenmannJ Offline
          Joel Bodenmann
          wrote on last edited by Joel Bodenmann
          #4

          Thank you for the answers, guys!

          QtSingleApplication appears to be some 3rd party solution, is that correct? It also seems not to be very active/commonly used. Is there another way of doing this using only what the Qt library itself provides?

          Industrial process automation software: https://simulton.com
          Embedded Graphics & GUI library: https://ugfx.io

          mrjjM kshegunovK 2 Replies Last reply
          0
          • Joel BodenmannJ Joel Bodenmann

            Thank you for the answers, guys!

            QtSingleApplication appears to be some 3rd party solution, is that correct? It also seems not to be very active/commonly used. Is there another way of doing this using only what the Qt library itself provides?

            mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by mrjj
            #5

            @Joel-Bodenmann

            I think @kshegunov made a nice new version.
            (sorry i remembered wrong, i think it was a demon class)

            Joel BodenmannJ 1 Reply Last reply
            0
            • mrjjM mrjj

              @Joel-Bodenmann

              I think @kshegunov made a nice new version.
              (sorry i remembered wrong, i think it was a demon class)

              Joel BodenmannJ Offline
              Joel BodenmannJ Offline
              Joel Bodenmann
              wrote on last edited by Joel Bodenmann
              #6

              We'll see what he has to add to this once he sees the highlight/notification :)

              At this point I'd like to point out that I WANT to give the user the ability to launch multiple instances of the same program. I want the same behavior as any other Windows software: User can spawn as many instances of the application as he likes, but selecting multiple files in the file explorer and hitting enter will launch only one new instance and pass ALL the selected files as command line parameters to that newly created instance.

              This looks fun too: https://github.com/itay-grudev/SingleApplication

              Industrial process automation software: https://simulton.com
              Embedded Graphics & GUI library: https://ugfx.io

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

                Hi,

                The repository might not be highly active but QtSingleApplication seems to be pretty used. There's currently a discussion about having it included in qtbase.

                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
                2
                • Joel BodenmannJ Joel Bodenmann

                  Thank you for the answers, guys!

                  QtSingleApplication appears to be some 3rd party solution, is that correct? It also seems not to be very active/commonly used. Is there another way of doing this using only what the Qt library itself provides?

                  kshegunovK Offline
                  kshegunovK Offline
                  kshegunov
                  Moderators
                  wrote on last edited by
                  #8

                  @Joel-Bodenmann

                  Is there another way of doing this using only what the Qt library itself provides?

                  There is - duplicating what the mentioned library does - that is opening a local socket and handling the command lines and IPC by hand.

                  Read and abide by the Qt Code of Conduct

                  1 Reply Last reply
                  0
                  • Joel BodenmannJ Offline
                    Joel BodenmannJ Offline
                    Joel Bodenmann
                    wrote on last edited by Joel Bodenmann
                    #9

                    Thank you guys!
                    I'm going to mark this topic as solved as the question has been answered. Actual implementation will be another problem :p

                    Industrial process automation software: https://simulton.com
                    Embedded Graphics & GUI library: https://ugfx.io

                    1 Reply Last reply
                    0

                    • Login

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