QML object type is not a type error in QTCreator

Hi all, I am new to QT and am having problems loading one qml through another qml. I basically created the qml MyTabView (MyTabView.qml)

import QtQuick 2.3 import QtQuick.Controls 1.2 TabView { width: 360 height: 360 Component.onCompleted: { addTab("Tab 1", tab1) addTab("Tab 2", tab2) } Component { id: tab1 Rectangle {color: "red"} } Component { id: tab2 Rectangle {color: "blue"} } } 

and I try to show it through another qml (main.qml) which is in the same directory

 import QtQuick 2.3 import QtQuick.Controls 1.2 import "." ApplicationWindow { visible: true width: 640 height: 480 title: qsTr("Main") MyTabView {} } 

but when I try to start my project, I get this error

QQmlApplicationEngine failed to load qrc component: /qml/main.qml: 11 TabView is not a type

Note that I have M Caps in MyTabView.qml and that MyTabView.qml and main.qml are in the same directory.

Can someone please tell me what mistake I am making? One thing I want to point out is that when I replace all MyTabView.qml code instead of MyTabView {} inside main.qml , the program gives no errors and works correctly. thanks in advance

+5
source share
3 answers

Have you added the file to your resources?
It is not possible to add your MyTabView.qml to your project in the same main.qml directory.
You need to put your QML file in Resources (perhaps main.qrc/qml/ ) for it to be deployed.
Qt Creator does not need this inclusion to find your type, so it does not detect errors.

+10
source

I had a similar problem.

qrc: AGview.qml: 8: 15: AGraph is not a type

I solved this: my original code (in my main.cpp):

 view.setSource(QUrl("qrc:AGview.qml")); 

working:

 view.setSource(QUrl("qrc:/AGview.qml")); 

I think that without a slash, it will not search in the actual folder.

+2
source

You should rename your "TabView.qml" to something like "MyTabView.qml".

Because of this, imports

 import "." 

your TabView conflicts with "QtQuick.Controls 1.2" and the local folder "."

0
source

Source: https://habr.com/ru/post/1207016/


All Articles