Qt5 QML in CLion - QQmlApplicationEngine failed to load component

Viewed 745

I'm getting an error while trying to get Qt .qml environment working in CLion, cause I don't really want to use QtCreator:

QQmlApplicationEngine failed to load component
qrc:/main.qml:2:1: module "QtQuick.Window" is not installed
qrc:/main.qml:1:1: module "QtQuick" is not installed
qrc:/main.qml:2:1: module "QtQuick.Window" is not installed
qrc:/main.qml:1:1: module "QtQuick" is not installed

No idea what's going on, made a huge research and I haven't found anything. My QML file I'm trying to run is:

import QtQuick 2.12
import QtQuick.Window 2.12

Window {
    width: 640
    height: 480
    visible: true
    title: qsTr("Hello World")
}

resources.qrc:

<RCC>
    <qresource>
        <file>main.qml</file>
    </qresource>
</RCC>

CMakeLists.txt: https://gist.github.com/zmatez/52d7a552d10d82beed8d86783b1322eb

CMake options:

-DCMAKE_PREFIX_PATH="E:/ProgramFiles/qt/5.15.2/mingw81_64/lib/cmake/Qt5"

main.cpp: https://gist.github.com/zmatez/52d7a552d10d82beed8d86783b1322eb

I was comparing it with auto-generated code with QtCreator, and my is almost identical as the creator's one. Also, QtWidgets application was working fine in CLion on my current configuration.

Thanks for any help

1 Answers

I was having the same issue. Thanks to @folibis' comment above my problem was solved. As suggested by him, I just had to add an environment variable QML2_IMPORT_PATH and set its value to %QTDIR%\qml.

In my case it was not CLion. It was an existing project which was using Qt Widgets for UI. It was to be changed to use QML instead. It was giving me all sorts of troubles while identifying the QtQuick module. I tried many things but nothing worked, but this trick worked like a charm.

Related