import qml error:no such directory
-
Look at the error in QQmlApplicationEngie failed means path is not properly Set....
-
@cuijg Also tell me exactly what are you trying to do ?Please Brief More
-
@cuijg Also tell me exactly what are you trying to do ?Please Brief More
@Shrishashank
The OP is clearly asking whyimport "../Constants.qml"
fails to find that file in the directory immediately above whereApp.qml
lives, given the hierarchical directory structure in the screenshots. -
@Shrishashank
The OP is clearly asking whyimport "../Constants.qml"
fails to find that file in the directory immediately above whereApp.qml
lives, given the hierarchical directory structure in the screenshots.@JonB Got it Jon ,The thing is I also getting the same issue, but intead of QCoreApplication::applicatioDirpath() i given the hardcode path where it works for me ,but this way is also good and also taking the absolute path of the Dir,
Thank you for you Input . -
@JonB Got it Jon ,The thing is I also getting the same issue, but intead of QCoreApplication::applicatioDirpath() i given the hardcode path where it works for me ,but this way is also good and also taking the absolute path of the Dir,
Thank you for you Input .@Shrishashank
I know nothing about QML so cannot answer the question. But this is animport
statement in code. Clearly that cannot use a hard-coded, absolute path as it must work from anywhere. Nor canQCoreApplication::applicatioDirpath()
or similar be used in animport
statement. It seems clear a relative path would be required. But the OP says../Constants.qml
, which looks to be correct (if QML allows it) to reach that file from whereApp.qml
is, apparently does not find it.@cuijg
Your situation is reported in e.g. https://forum.qt.io/topic/98165/import-with-relative-path. There the OP fails on..
. The solution there claims you are supposed to writeimport ":/../Constants.qml"
Note the leading
:/
. Try that?[UPDATE: Sorry, no, that appears to be for a resource file, like an icon, not a source code file.]
However I note that seems in contradiction to Qt docs at https://doc.qt.io/qt-6/qtqml-syntax-directoryimports.html, which does imply your plain
../...
should work. As I said, I know nothing :) So good luck. -
@Shrishashank
I know nothing about QML so cannot answer the question. But this is animport
statement in code. Clearly that cannot use a hard-coded, absolute path as it must work from anywhere. Nor canQCoreApplication::applicatioDirpath()
or similar be used in animport
statement. It seems clear a relative path would be required. But the OP says../Constants.qml
, which looks to be correct (if QML allows it) to reach that file from whereApp.qml
is, apparently does not find it.@cuijg
Your situation is reported in e.g. https://forum.qt.io/topic/98165/import-with-relative-path. There the OP fails on..
. The solution there claims you are supposed to writeimport ":/../Constants.qml"
Note the leading
:/
. Try that?[UPDATE: Sorry, no, that appears to be for a resource file, like an icon, not a source code file.]
However I note that seems in contradiction to Qt docs at https://doc.qt.io/qt-6/qtqml-syntax-directoryimports.html, which does imply your plain
../...
should work. As I said, I know nothing :) So good luck. -
I succeeded, but it looks very strange:
Step 1: Add to CMakeLists.txt:
set_source_files_properties(Constants.qml
PROPERTIES
QT_QML_SINGLETON_TYPE TRUE
)
Step 2: There is no need to explicitly reference Constants.qml in App. qmlAs a result, the operation was successful
-
This import does not import a file, but a directory, which is why the above error is always reported: no such directory
I understand a little bit now. The use of qml is like the classes and objects of c++. What are defined in the qml file are types. When using them, they cannot be directly referenced by the type name (unless a singleton object is defined). Instead, an object instance should be created using the type defined in qml, and then this instance object should be referenced.
For example:
-