I'm having trouble loading one qml through another.
Basically, I have created a qml type MyTabView
in 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 use it in another qml file (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
Notes:
I have M Caps in
MyTabView.qml
and it's in the same directory asmain.qml
.When I replace all the code of
MyTabView.qml
instead ofMyTabView {}
insidemain.qml
, the program does not give any error and runs correctly.
What am I doing wrong and how to fix it ?
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 "."