[solved]how to import from the qrc?
-
Hi,
I push the Page into the PageStack use:
@
pagestack.push(Qt.resolveUrl("qrc:/qml/page/MyPage"));
@then, in the MyPage.qml:
@
import QtQuick 1.0
import "../ui" as UI
@But it seems that the MyPage cannot find the ui directory.
If I do not use qrc to load MyPage, the use of import *"../ui" as UI *work perfectly.
so how to deal with this situation?
-
try following
@import ":/qml/UI" as UI@
-
Could "QDeclarativeEngine::addImportPath":http://doc.qt.nokia.com/4.7/qdeclarativeengine.html#addImportPath possibly help?
-
[quote author="mlong" date="1313603718"]Could "QDeclarativeEngine::addImportPath":http://doc.qt.nokia.com/4.7/qdeclarativeengine.html#addImportPath possibly help? [/quote]
It seems doesn't work with my situation.
I just donn't know how to import the component from the qrc
-
Hi,
It looks like your setup is a bit different from the approach described at http://doc.qt.nokia.com/4.7-snapshot/qtbinding.html#managing-resource-files-with-the-qt-resource-system. It might be worth reworking your code to match the structure there, if possible (basically, use qrc when loading the initial file from C++, and relative paths everywhere inside QML). If that doesn't work, I'd suggest filing a bug via http://bugreports.qt.nokia.com
Regards,
Michael -
[quote author="mbrasser" date="1313707194"]Hi,
It looks like your setup is a bit different from the approach described at http://doc.qt.nokia.com/4.7-snapshot/qtbinding.html#managing-resource-files-with-the-qt-resource-system. It might be worth reworking your code to match the structure there, if possible (basically, use qrc when loading the initial file from C++, and relative paths everywhere inside QML). If that doesn't work, I'd suggest filing a bug via http://bugreports.qt.nokia.com
Regards,
Michael[/quote]Hi, thanks for your reply. I have just gotten over it. I use the addImportPath() to regist my import path. and then I can import like this:
@
//in cppengine->addImportPath(""qrc:/);
//in qml
import "qrc:/qml/ui" as UI
@
At this time, the Qt Creator IDE will surely regard it as a fault that cannot find the path or file.
But when recompiled my project, it worked as expected. So, the Qt IDE confused me. Maybe it's
a bug of Qt Creator.