Hi Everyone i am new to QT and i am having trouble loading one qml through another qml Basically i have created a 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 am trying 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 run my project i get this error
QQmlApplicationEngine failed to load component qrc:/qml/main.qml:11 TabView is not a type
Please note that i have M Caps in MyTabView.qml and that MyTabView.qml and main.qml are in the same directory.
Can someone point me what mistake i am doing ?
One thing i want to point is that when i replace all the code of MyTabView.qml instead of MyTabView {}
inside main.qml
,the program does not give any error and runs correctly.
Thanks in advance
You should rename your "TabView.qml" to something like "MyTabView.qml".
Because of that import
you have conflict of TabView from "QtQuick.Controls 1.2" and local folder "."
Have you added the file to your Resources ?
Adding your
MyTabView.qml
to your project in the same directory ofmain.qml
is not sufficient.You have to put your QML file in the Resources (probably
main.qrc/qml/
) in order to have it deployed.The editor of Qt Creator does not need this inclusion in order to find your type, therefore it displays no error.
I had a similar problem.
I solved it: my original code (in my main.cpp):
the working one:
I think without the slash it don't search in the actual folder.