Important: Please read the Qt Code of Conduct -

Qml file not getting found after adding to a resource file

  • Hi,

    I have got the following project :

    The main.cpp file in it reads as follows :
    @#include <QGuiApplication>
    #include <QQuickView>
    int main(int argc, char* argv[])
    QGuiApplication app(argc,argv);
    QQuickView view;
    return app.exec();

    The qml is in main.qml which I have added to the resource:
    <qresource prefix="/">

    But I still get an error :
    Starting F:\Code\Qt\build-RapidConcepts-Desktop_Qt_5_2_1_MSVC2012_32bit-Debug\debug\RapidConcepts.exe...
    QML debugging is enabled. Only use this in a safe environment.
    file:///F:/Code/Qt/build-RapidConcepts-Desktop_Qt_5_2_1_MSVC2012_32bit-Debug/:/main.qml: File not found

    1. There is no prefix for the resource. I have accessed it using the propoer qrc syntax. Yet I do not get why its unable to find it.

    2. I want to make this application a mixed QML and C++ application. So when I created the project I got this class by default which was used in main.cpp :


    #include <QtQuick/QQuickView>

    class QtQuick2ApplicationViewer : public QQuickView

    explicit QtQuick2ApplicationViewer(QWindow *parent = 0);
    virtual ~QtQuick2ApplicationViewer();

    void setMainQmlFile&#40;const QString &file&#41;;
    void addImportPath(const QString &path);
    void showExpanded();

    class QtQuick2ApplicationViewerPrivate *d;

    Why do I have to use this class at all. Cant I just use QQuickView directly as in the code I have given at the top of this post ? Why does Qt generate this extra class at all ?

  • Moderators

    Use this instead:

  • Thanks for the reply sierdzio. But it does not work :(

    file:///F:/Code/Qt/build-RapidConcepts-Desktop_Qt_5_2_1_MSVC2012_32bit-Debug/:/main.qml: File not found

  • clean your project and build again and then run. And make sure your .qrc was added in .pro

  • Tried that and checked that respectively. No luck :(
    The error is exactly the same.

    Here is my pro:

    @# Add more folders to ship with the application, here
    folder_01.source = qml/RapidConcepts = qml

    Additional import path used to resolve QML modules in Creator's code model


    The .cpp file which was generated for your project. Feel free to hack it.

    SOURCES += main.cpp

    Installation path

    target.path =

    Please do not modify the following two lines. Required for deployment.




  • Moderators

    BTW: as you correctly assume, you do not need to use QtQuick2ApplicationViewer. QQuickView is absolutely enough.

    Are you sure your resource file is being compiled and included in the binary? Have you added something like this to your .pro file:
    RESOURCES += myResourceFile.rcc

    Plus, just in case, try this:

  • Thanks so much. I went and deleted the build directory. Then rebuilt and it worked. Phew ! even a clean all from qt creator could not fix this.

    By the way does qtquick2applicationviewer - the QQuickView dreived class, provide any benefits at all when writing mixed qml + c++ applications ?

  • No problem, I got the answer from the header :

    bq. This file was generated by the Qt Quick 2 Application wizard of Qt Creator.
    QtQuick2ApplicationViewer is a convenience class containing mobile device specific
    code such as screen orientation handling. Also QML paths and debugging are
    handled here.

  • Moderators

    [quote author="modeldancecontroller" date="1391876969"]By the way does qtquick2applicationviewer - the QQuickView dreived class, provide any benefits at all when writing mixed qml + c++ applications ?[/quote]

    No. I am amazed this thing is still in use. It was created for Symbian back in the Nokia days and has remained present in Qt Creator till today. Personally I never use it, but it might indeed help some people in getting started, especially with Android.

  • i had this problem too : just disable qt quick compiler

Log in to reply