Qt Forum

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

    Update: Forum Guidelines & Code of Conduct


    Qt World Summit: Early-Bird Tickets

    How to getting the application dir in QML file

    QML and Qt Quick
    7
    12
    11819
    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.
    • L
      lygstate last edited by

      I wan't to do relative path evaluation.

      1 Reply Last reply Reply Quote 0
      • p3c0
        p3c0 Moderators last edited by

        Hi,

        Check "resolvedUrl":http://qt-project.org/doc/qt-5/qml-qtqml-qt.html#resolvedUrl-method if its useful.
        To get current directory try,
        @
        Qt.resolvedUrl(".")
        @

        157

        1 Reply Last reply Reply Quote 1
        • L
          lygstate last edited by

          I hope this works, but the fact is that didn't satisfy my requirement
          source: {
          console.log(Qt.resolvedUrl("./../"))
          return "D:/CI/AVA/PedestrianV2/data/subway.avi"
          }

          1 Reply Last reply Reply Quote 0
          • p3c0
            p3c0 Moderators last edited by

            Sorry but can you make more clear how you want the path ?

            157

            1 Reply Last reply Reply Quote 0
            • L
              lygstate last edited by

              sorry for unclear statement, I checked the result ofQt.resolvedUrl("."), Its give s me qrc:/// and that's not I wanted, I want the absolute path of the application's executable file's containing directory. such as
              @D:/path/to/demo.exe @
              then I am looking for
              @D:/path/to/@

              1 Reply Last reply Reply Quote 0
              • p3c0
                p3c0 Moderators last edited by

                Hi,

                @lygstate, have you included the QML file in the qrc ?

                157

                1 Reply Last reply Reply Quote 0
                • L
                  lygstate last edited by

                  Yes, you are right, i included it in qrc file,

                  1 Reply Last reply Reply Quote 0
                  • E
                    Eddy last edited by

                    Try

                    @QDir::currentpath()@

                    And pass the result to your qml file

                    Qt Certified Specialist
                    www.edalsolutions.be

                    1 Reply Last reply Reply Quote 0
                    • A
                      aabc last edited by

                      I also using the C++ and I believe the performance is better

                      1 Reply Last reply Reply Quote 0
                      • C
                        chrisadams last edited by

                        You can use the baseUrl() reported by the engine.

                        1 Reply Last reply Reply Quote 0
                        • N
                          NapoLion last edited by

                          Hello!
                          I know its an old post, but I came across and didn't find what I was looking for so I solved it like this:

                          In your main.cpp add one new context property to your engine like this:

                          engine.rootContext()->setContextProperty("CurDirPath", QString(QDir::currentPath()));
                          

                          Than use it on your Qml side like:

                          Component.onCompleted: {
                              console.log("Your current dir path: " + CurDirPath)
                          }
                          

                          Hope it helps for future visitors.

                          JonB 1 Reply Last reply Reply Quote 2
                          • JonB
                            JonB @NapoLion last edited by JonB

                            @NapoLion
                            For anyone reading this: the question title asked for "application dir ". All solutions using QDir::currentPath(), or for that matter QDir(), do not return that, they return the process's current/working directory

                            Depending on what .is meant by "the application dir", you may want QCoreApplication::applicationDirPath() or even QFileInfo(argv[0]).dir().absolutePath(), but I don't know how those fare with a QML application.

                            1 Reply Last reply Reply Quote 2
                            • First post
                              Last post