Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. How to getting the application dir in QML file
Qt 6.12 LTS is out! See what's new in the release blog

How to getting the application dir in QML file

Scheduled Pinned Locked Moved QML and Qt Quick
12 Posts 7 Posters 16.3k Views 1 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.
  • L Offline
    L Offline
    lygstate
    wrote on last edited by
    #3

    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
    0
    • p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #4

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

      157

      1 Reply Last reply
      0
      • L Offline
        L Offline
        lygstate
        wrote on last edited by
        #5

        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
        0
        • p3c0P Offline
          p3c0P Offline
          p3c0
          Moderators
          wrote on last edited by
          #6

          Hi,

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

          157

          1 Reply Last reply
          0
          • L Offline
            L Offline
            lygstate
            wrote on last edited by
            #7

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

            1 Reply Last reply
            0
            • EddyE Offline
              EddyE Offline
              Eddy
              wrote on last edited by
              #8

              Try

              @QDir::currentpath()@

              And pass the result to your qml file

              Qt Certified Specialist
              www.edalsolutions.be

              1 Reply Last reply
              0
              • ? Offline
                ? Offline
                A Former User
                wrote on last edited by
                #9

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

                1 Reply Last reply
                0
                • C Offline
                  C Offline
                  chrisadams
                  wrote on last edited by
                  #10

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

                  1 Reply Last reply
                  0
                  • N Offline
                    N Offline
                    NapoLion
                    wrote on last edited by
                    #11

                    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.

                    JonBJ 1 Reply Last reply
                    3
                    • N NapoLion

                      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.

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

                      @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
                      3

                      • Login

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