Qrc : cannot find file/directory issues



  • Hi All,

    I am working on a project in which all .cpp and .qml files are stored in the Qt Resource file(.qrc).
    I have tried to import an external directory in one of a qml file. The external directory contains
    other .qml files for different purposes.
    I don't want to include these external directory into the .qrc file.

    I got an error when i add the import path saying that "qrc:\example.qml : cannot find directory". Is there any way to include an external file or directory like this.

    Regards
    Ansif


  • Moderators

    Try with "file:/path" to tell QML you are breaking free from QRC. Or you can clear the context in the QML engine, but that will work only for Loader items.

    Why on Earthe do you include your c++ files in the QRC?



  • Hi,

    Thanks for your reply. I will try this and will let you know. It was a mistake in my question, I included only .qml, javascript and image files in the QRC. Sorry for the mistake.

    Regards
    ansif



  • Hi Again,

    I have tried to import like "#import "file:/../qml" as Tester" and i called Tester.PaletteModel {}, It shows an error like "qrc:/EditorPalette.qml:4:1: "file:/qml": no such directory ".

    EditorPAlette.qml is stored in the QRC and qml is the directory where PaletteModel.qml is the external file that is required.

    Regards
    ansif


  • Moderators

    Sorry it's been almost 2 years since I had a similar problem, I don't remember a solution :( Try asking on interest mailing list, there are more Qt devs there.

    I vaguely recall that there were some updates in that area for QML2, if possible try this with Qt 5.1.



  • Hi Slerdizlo,

    Recently i got a solution for the question that i have asked and I want to write it in here. May be some others are also got this issue,
    I got the solution from the Qt forum, http://qt-project.org/forums/viewthread/7047
    Thanks to Denis Kormalev, Volker and Brucewuu for solving this problem.

    If you can go through this link, you can easily understand it. For accessing any file outside QRC, use "absolute filepath" of the file.
    For example:
    In main.cpp file;
    QString path = QDir::currentPath(); //path where the exec is present
    if your file is in src/file.qml of exec folder, then you can access it like
    (path += "/src/file.qml";), now path is the absolute file path for file.qml. You can access it in any of the QRC file.
    QQuickView view;
    view.rootContext()->setContextProperty("myFile", path);
    view.setSource("qrc:/main.qml");

    In main.qml file:
    Loader
    {
    id: loadItem
    source: myFile
    }
    Item
    {
    Component.onCompleted: loadItem.item
    }

    Regards
    Ansif


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.