Cannot import directory in resources
-
I have a qrc file which contains:
/qml/main.qml /qml/scene/CityScene.qml
When I write
import "scene"
in main.qml, it prints:QQmlApplicationEngine failed to load component file::/qml/main.qml:19 import "scene" has no qmldir and no namespace
If I change
import "scene"
toimport "qrc:/qml/scene"
, it just works fine.
But this is very annoying because whenever importing directory, it makes me write full absolute directory path.
Futhermore, I'm using qrc file only for releasing and I don't use qrc file during developing/debugging.
If I have to write always absolute path for QML file in resources, I have to write two sets of QML file which differ for only import statements.How can I make
import "scene"
work with QML file in qrc file here?FYI, I've tried to add
/qml/scene/qmldir
file but it didn't work. -
QML engine assumes the loading source base on how you call QQmlEngine::load(). If you use QRC there, it will be used for all
import
statements in QML, too. If you use relative path inload()
, it will use relative paths in QML as well. If you use shadow building (the default), it means that it will look for "scene" directory in your build dir.Hope it helps :-) There is also a way to disable QRC temporarily, I've described it here: link.
I do recommend, however, to use QRC both for production and development - you'll have no issues at all :-)
-
Hello, I'm having a similar issue, except I would like to reference my QRC imports via an absolute path, as they are spread out amongst many plugins. This is with Qt 5.9.1.
e.g. In the example given here, it would be:
import "/scene"
I'm porting a large project from Qt4, where this worked just fine. I also had this running with an older version of Qt5 (can't quite remember which one).
I know I can replace all of my imports with
import "qrc:/scene"
, but I'd like to avoid that, as I'm then tied to the QRC system.Is there any possible workaround, or has this functionality just been completely removed?
-
Hello, I'm having a similar issue, except I would like to reference my QRC imports via an absolute path, as they are spread out amongst many plugins. This is with Qt 5.9.1.
e.g. In the example given here, it would be:
import "/scene"
I'm porting a large project from Qt4, where this worked just fine. I also had this running with an older version of Qt5 (can't quite remember which one).
I know I can replace all of my imports with
import "qrc:/scene"
, but I'd like to avoid that, as I'm then tied to the QRC system.Is there any possible workaround, or has this functionality just been completely removed?
@stephen.m.dangelo said in Cannot import directory in resources:
I know I can replace all of my imports with import "qrc:/scene", but I'd like to avoid that, as I'm then tied to the QRC system.
Is there any possible workaround, or has this functionality just been completely removed?Use QRC to load your main.qml. Then all files inside main.qml will default to QRC as well and you will be able to use
import "scene"
.