Qml file not getting found after adding to a resource file
-
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-
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.
-
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_OBJECTpublic:
explicit QtQuick2ApplicationViewer(QWindow *parent = 0);
virtual ~QtQuick2ApplicationViewer();void setMainQmlFile(const QString &file); 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 ?
-
-
Use this instead:
@
view.setSource(QUrl("qrc:/main.qml"));
@ -
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
folder_01.target = qml
DEPLOYMENTFOLDERS = folder_01Additional 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.qrcOTHER_FILES +=
main.qml
@ -
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"));
@ -
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. -
[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.