I am trying to use QT Quick (QML) with Visual Studio 2015 and CMake. I started with an example "QT Quick Controls - Gallery" and transfered it to CMake. It works fine in QT Creator (using Visual Studio's compiler), but not in Visual Studio (solution generated with CMake GUI):
QQmlApplicationEngine failed to load component
qrc:/main.qml:-1 File not found
I have tried to isolate the problem and found this wonderful example: https://github.com/mattfife/QtQuick-with-cmake, which works (after some modifications) in QT Creator, but has the exactly same problem in Visual Studio.
The qml.qrc file is like this:
<RCC>
<qresource prefix="/">
<file>main.qml</file>
</qresource>
</RCC>
For both environments (QT Creator and Visual Studio), I have in the build directory a file src/qml.qrc.depends, whose content is exactly the previous qml file.
The important part in the main.cpp:
QQmlApplicationEngine engine;
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
if (engine.rootObjects().isEmpty())
return -1;
The error can be reproduced in QT Creator if I eliminate the next line in the CMakeLists.txt file:
qt5_add_resources(qml_QRC src/qml.qrc)
Any idea of how to solve it or what to try ? By example, I have no idea how to debug this QQmlApplicationEngine object.
Make sure you added a generated file (I assume it's qrc_qml.cpp in your case) into your project. In Visual Studio, when you right-click on qml.qrc, there is a Compile option (or Ctrl+F7). This will generate a cpp file from your qml.qrc. it is usually generated in GeneratedFiles folder.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With