How to getting the application dir in QML file
-
I wan't to do relative path evaluation.
-
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(".")
@ -
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"
} -
Sorry but can you make more clear how you want the path ?
-
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/@ -
Hi,
@lygstate, have you included the QML file in the qrc ?
-
Yes, you are right, i included it in qrc file,
-
Try
@QDir::currentpath()@
And pass the result to your qml file
-
I also using the C++ and I believe the performance is better
-
You can use the baseUrl() reported by the engine.
-
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.
-
@NapoLion
For anyone reading this: the question title asked for "application dir ". All solutions usingQDir::currentPath()
, or for that matterQDir()
, do not return that, they return the process's current/working directoryDepending on what .is meant by "the application dir", you may want
QCoreApplication::applicationDirPath()
or evenQFileInfo(argv[0]).dir().absolutePath()
, but I don't know how those fare with a QML application.