Qt5 QML Unknown component
-
wrote on 6 Jun 2024, 06:42 last edited by
Because of the need of work, I changed build system from qmake to cmake.
I found a problem that the program works properly, but calls MyRectangle.qml under other files in main.qml to prompt Unknown component. (M300),
On qmake, this problem does not exist as long as qrc is prefixed with "/". just like this
what should I do?Qt version: Qt 5.15.2
Build system: CMakecmake_minimum_required(VERSION 3.14) project(untitled VERSION 0.1 LANGUAGES CXX) ...... find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core Quick) find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core Quick) set(PROJECT_SOURCES main.cpp qml.qrc ./Extend/extend.qrc ) if(${QT_VERSION_MAJOR} GREATER_EQUAL 6) qt_add_executable(untitled MANUAL_FINALIZATION ${PROJECT_SOURCES} ) ......
The structure of the whole project is shown in the figure
main.qml
import QtQuick 2.15 import QtQuick.Window 2.15 Window { width: 640 height: 480 visible: true MyRectangle{ ----- UnKnown component. (M300) anchors.fill: parent } }
MyRectangle.qml
import QtQuick 2.15 import QtQuick.Controls 2.15 Rectangle { Label{ anchors.centerIn: parent text: "hello world" } }
I have tried to add qrc files using qt5_add_resources,and try Tools > QML/JS > Reset Code Model but the problem still exists
In my opinion, Maybe it's a good idea for me to use QML_DIR to turn qml into a module?
Thanks.... -
Yup, that's pretty normal. Qt Creator is not very clever when it comes to QML and custom components.
-
So the app works fine, and only in Qt Creator you get this M300 warning? I just ignore this.
-
So the app works fine, and only in Qt Creator you get this M300 warning? I just ignore this.
-
Yup, that's pretty normal. Qt Creator is not very clever when it comes to QML and custom components.
-
Yup, that's pretty normal. Qt Creator is not very clever when it comes to QML and custom components.
-
I don't know, I'm also stuck on Qt 5 ;-)
-
1/7