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 to find the path of the file that launches the Qt application from explorer
Forum Updated to NodeBB v4.3 + New Features

How to find the path of the file that launches the Qt application from explorer

Scheduled Pinned Locked Moved Unsolved General and Desktop
19 Posts 5 Posters 7.6k Views 3 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.
  • sierdzioS sierdzio

    @JNBarchan said in How to find the path of the file that launches the Qt application from explorer:

    So [0] is never to be used. I suspect @sierdzio was intending arguments()[1] maybe.

    Yes, my bad, sorry! I've corrected the post.

    Q Offline
    Q Offline
    QtVik
    wrote on last edited by
    #9

    @sierdzio @JNBarchan @mrjj :

    Thanks for your inputs.
    But this line is causing an assertion failure "index out of range" in qlist.h line#510
    qDebug() << "File path:" << args.at(1);

    Qt version used is 5.5.1

    Thanks

    sierdzioS 1 Reply Last reply
    0
    • Q QtVik

      @sierdzio @JNBarchan @mrjj :

      Thanks for your inputs.
      But this line is causing an assertion failure "index out of range" in qlist.h line#510
      qDebug() << "File path:" << args.at(1);

      Qt version used is 5.5.1

      Thanks

      sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by sierdzio
      #10

      @QtVik said in How to find the path of the file that launches the Qt application from explorer:

      @sierdzio @JNBarchan @mrjj :
      But this line is causing an assertion failure "index out of range" in qlist.h line#510
      qDebug() << "File path:" << args.at(1);

      Try printing all args:

      qDebug() << "File path:" << args;
      

      This will show you all arguments (apart from ones consumed by Qt).

      (Z(:^

      Q 1 Reply Last reply
      0
      • sierdzioS sierdzio

        @QtVik said in How to find the path of the file that launches the Qt application from explorer:

        @sierdzio @JNBarchan @mrjj :
        But this line is causing an assertion failure "index out of range" in qlist.h line#510
        qDebug() << "File path:" << args.at(1);

        Try printing all args:

        qDebug() << "File path:" << args;
        

        This will show you all arguments (apart from ones consumed by Qt).

        Q Offline
        Q Offline
        QtVik
        wrote on last edited by
        #11

        @sierdzio
        Actually I want path of the file which is invoking my application not the path of my application.exe.

        Example:
        I have a file named "sample.dat" in "C:\Meas folder" and Qt application in "C:\QApplication\Qapp.exe"
        Now if I double click on the "sample.dat " I should be able to find this path (C:\Meas folder) through my Qt application ie. Qapp.exe

        Thanks

        JonBJ sierdzioS 2 Replies Last reply
        0
        • Q QtVik

          @sierdzio
          Actually I want path of the file which is invoking my application not the path of my application.exe.

          Example:
          I have a file named "sample.dat" in "C:\Meas folder" and Qt application in "C:\QApplication\Qapp.exe"
          Now if I double click on the "sample.dat " I should be able to find this path (C:\Meas folder) through my Qt application ie. Qapp.exe

          Thanks

          JonBJ Online
          JonBJ Online
          JonB
          wrote on last edited by
          #12

          @QtVik
          @mrjj's post earlier shows you him doing this.

          You should still show us qDebug() << "File path:" << args as requested by @QtVik above.

          1 Reply Last reply
          0
          • Q QtVik

            @sierdzio
            Actually I want path of the file which is invoking my application not the path of my application.exe.

            Example:
            I have a file named "sample.dat" in "C:\Meas folder" and Qt application in "C:\QApplication\Qapp.exe"
            Now if I double click on the "sample.dat " I should be able to find this path (C:\Meas folder) through my Qt application ie. Qapp.exe

            Thanks

            sierdzioS Offline
            sierdzioS Offline
            sierdzio
            Moderators
            wrote on last edited by
            #13

            @QtVik said in How to find the path of the file that launches the Qt application from explorer:

            Actually I want path of the file which is invoking my application not the path of my application.exe.

            I know, that's what we are trying to help you with.

            Actually, apart from using QCoreApplication::arguments(), you may also consider using QDir::currentPath().

            (Z(:^

            JonBJ 1 Reply Last reply
            1
            • sierdzioS sierdzio

              @QtVik said in How to find the path of the file that launches the Qt application from explorer:

              Actually I want path of the file which is invoking my application not the path of my application.exe.

              I know, that's what we are trying to help you with.

              Actually, apart from using QCoreApplication::arguments(), you may also consider using QDir::currentPath().

              JonBJ Online
              JonBJ Online
              JonB
              wrote on last edited by
              #14

              @sierdzio said in How to find the path of the file that launches the Qt application from explorer:

              you may also consider using QDir::currentPath().

              Do you have any evidence/knowledge that launching by double-clicking from Windows Explorer sets the application's current directory to that of the file double-clicked on??

              sierdzioS 1 Reply Last reply
              0
              • JonBJ JonB

                @sierdzio said in How to find the path of the file that launches the Qt application from explorer:

                you may also consider using QDir::currentPath().

                Do you have any evidence/knowledge that launching by double-clicking from Windows Explorer sets the application's current directory to that of the file double-clicked on??

                sierdzioS Offline
                sierdzioS Offline
                sierdzio
                Moderators
                wrote on last edited by
                #15

                @JNBarchan said in How to find the path of the file that launches the Qt application from explorer:

                @sierdzio said in How to find the path of the file that launches the Qt application from explorer:

                you may also consider using QDir::currentPath().

                Do you have any evidence/knowledge that launching by double-clicking from Windows Explorer sets the application's current directory to that of the file double-clicked on??

                Nope, it's just a guess.

                (Z(:^

                1 Reply Last reply
                0
                • Q QtVik

                  Hello,

                  I have a *.dat file that can be opened in my qt application.
                  Now i want to check, from the explorer which file format / path of the file that user is trying to use to launch my application.

                  How to achieve that ?

                  Best regards

                  JonBJ Online
                  JonBJ Online
                  JonB
                  wrote on last edited by
                  #16

                  @QtVik
                  If you would just show us your output from GetCommandLine(), QCoreApplication::instance()->arguments() and/or your main()'s argv, argc we could tell you what to do....

                  Q 1 Reply Last reply
                  0
                  • JonBJ JonB

                    @QtVik
                    If you would just show us your output from GetCommandLine(), QCoreApplication::instance()->arguments() and/or your main()'s argv, argc we could tell you what to do....

                    Q Offline
                    Q Offline
                    QtVik
                    wrote on last edited by
                    #17

                    @JNBarchan
                    Following are the values for const QStringList args(QApplication::instance()->arguments()), argc ,argv:
                    1] argc value is 1
                    2] argv value is the application path .
                    3] args.at(0) value is also application path .
                    4] args.at(1) -> crash the application .

                    The above values are shown when I double click on the application directly.

                    But this is not what i want !

                    I want path of the file that is trying to invoke my application from explorer.
                    Example: from the previous post it should be "C:\Meas_folder\sample.dat"

                    Note: I have set my Qapp.exe as default application to open for sample.dat

                    Thanks

                    jsulmJ 1 Reply Last reply
                    0
                    • Q QtVik

                      @JNBarchan
                      Following are the values for const QStringList args(QApplication::instance()->arguments()), argc ,argv:
                      1] argc value is 1
                      2] argv value is the application path .
                      3] args.at(0) value is also application path .
                      4] args.at(1) -> crash the application .

                      The above values are shown when I double click on the application directly.

                      But this is not what i want !

                      I want path of the file that is trying to invoke my application from explorer.
                      Example: from the previous post it should be "C:\Meas_folder\sample.dat"

                      Note: I have set my Qapp.exe as default application to open for sample.dat

                      Thanks

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

                      @QtVik Please provide same information for the case you are interested in! It doesn't help at all if you double click your app and then post the results here: this is not the use case you're interested in, right?
                      So, open you app from explorer with a data file and post the content of QApplication::instance()->arguments() here...

                      "Note: I have set my Qapp.exe as default application to open for sample.dat" - then it should be enough to double click on sample.dat and post the output of QApplication::instance() here.

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

                      JonBJ 1 Reply Last reply
                      3
                      • jsulmJ jsulm

                        @QtVik Please provide same information for the case you are interested in! It doesn't help at all if you double click your app and then post the results here: this is not the use case you're interested in, right?
                        So, open you app from explorer with a data file and post the content of QApplication::instance()->arguments() here...

                        "Note: I have set my Qapp.exe as default application to open for sample.dat" - then it should be enough to double click on sample.dat and post the output of QApplication::instance() here.

                        JonBJ Online
                        JonBJ Online
                        JonB
                        wrote on last edited by
                        #19

                        @jsulm
                        Exactly... sigh.

                        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