Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    Solved Command line arguments multiple file paths

    General and Desktop
    5
    9
    2169
    Loading More Posts
    • 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 Bodenmann
      Joel Bodenmann last edited by 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.

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

      raven-worx 1 Reply Last reply Reply Quote 0
      • raven-worx
        raven-worx Moderators @Joel Bodenmann last edited by

        @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 Bodenmann 1 Reply Last reply Reply Quote 2
        • mrjj
          mrjj Lifetime Qt Champion last edited by mrjj

          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 Reply Quote 0
          • Joel Bodenmann
            Joel Bodenmann @raven-worx last edited by 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?

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

            mrjj kshegunov 2 Replies Last reply Reply Quote 0
            • mrjj
              mrjj Lifetime Qt Champion @Joel Bodenmann last edited by mrjj

              @Joel-Bodenmann

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

              Joel Bodenmann 1 Reply Last reply Reply Quote 0
              • Joel Bodenmann
                Joel Bodenmann @mrjj last edited by Joel Bodenmann

                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 Reply Quote 0
                • SGaist
                  SGaist Lifetime Qt Champion last edited by

                  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 Reply Quote 2
                  • kshegunov
                    kshegunov Moderators @Joel Bodenmann last edited by

                    @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 Reply Quote 0
                    • Joel Bodenmann
                      Joel Bodenmann last edited by Joel Bodenmann

                      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 Reply Quote 0
                      • First post
                        Last post