Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Qml file not getting found after adding to a resource file
QtWS25 Last Chance

Qml file not getting found after adding to a resource file

Scheduled Pinned Locked Moved QML and Qt Quick
10 Posts 4 Posters 8.4k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    modeldancecontroller
    wrote on last edited by
    #1

    Hi,

    I have got the following project : http://www.datafilehost.com/d/3e0d49d0

    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;
    view.setSource(QUrl(":/main.qml"));
    view.setResizeMode(QQuickView::SizeRootObjectToView);
    view.show();
    return app.exec();
    }
    @

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

    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 :

    @#ifndef QTQUICK2APPLICATIONVIEWER_H
    #define QTQUICK2APPLICATIONVIEWER_H

    #include <QtQuick/QQuickView>

    class QtQuick2ApplicationViewer : public QQuickView
    {
    Q_OBJECT

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

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

    private:
    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 ?

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      Use this instead:
      @
      view.setSource(QUrl("qrc:/main.qml"));
      @

      (Z(:^

      1 Reply Last reply
      0
      • M Offline
        M Offline
        modeldancecontroller
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        • V Offline
          V Offline
          Vincent007
          wrote on last edited by
          #4

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

          1 Reply Last reply
          0
          • M Offline
            M Offline
            modeldancecontroller
            wrote on last edited by
            #5

            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
            folder_01.target = qml
            DEPLOYMENTFOLDERS = folder_01

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

            QML_IMPORT_PATH =

            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.

            include(qtquick2applicationviewer/qtquick2applicationviewer.pri)
            qtcAddDeployment()

            RESOURCES +=
            rapidconcepts.qrc

            OTHER_FILES +=
            main.qml
            @

            1 Reply Last reply
            0
            • sierdzioS Offline
              sierdzioS Offline
              sierdzio
              Moderators
              wrote on last edited by
              #6

              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:
              @
              view.setSource(QUrl::fromUserInput("qrc:/main.qml"));
              @

              (Z(:^

              1 Reply Last reply
              0
              • M Offline
                M Offline
                modeldancecontroller
                wrote on last edited by
                #7

                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 ?

                1 Reply Last reply
                0
                • M Offline
                  M Offline
                  modeldancecontroller
                  wrote on last edited by
                  #8

                  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.

                  1 Reply Last reply
                  0
                  • sierdzioS Offline
                    sierdzioS Offline
                    sierdzio
                    Moderators
                    wrote on last edited by
                    #9

                    [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.

                    (Z(:^

                    1 Reply Last reply
                    0
                    • H Offline
                      H Offline
                      haftado3
                      wrote on last edited by
                      #10

                      i had this problem too : just disable qt quick compiler

                      1 Reply Last reply
                      0

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved