Quick 2.0 import delegate
-
Hey I have the following code.
And I didn't manage to import a delegate from a file.
I get the Error
@views/GridView.qml:19: ReferenceError: Elements is not defined@main.qml
@
import "views"Item {
width: 700
height: 360
Rectangle {
anchors.fill: parent
GridView {
anchors.fill: parent
}
}
}@views/GridView.qml
@import QtQuick 2.0
import "../elements/" as Elements
Item {
id: grid_view
width: 100
height: 62
Rectangle {
id: grid_view_bg
anchors.fill: parent
ListView {
anchors.fill: parent
model: employee_model
orientation: Qt.Horizontal
delegate: Elements.EmployeeDelegate
}
}
}@elements/EmployeeDelegate.qml
@import QtQuick 2.0Component {
Item {
id:employeeContainer
width: 180;
height: parent.height
Rectangle {
id:employeeBody
anchors.fill: parent
anchors.rightMargin: 5
color: "red"
border.color: "black"
Rectangle {
id: employeeHeader
color: "#bbdbf3"
anchors.horizontalCenter: parent.horizontalCenter
width: parent.width
height: 40Text { anchors.centerIn: parent text: '<b>Name:</b> ' + employee.name } border.color: "black" } Item { id: clipContainer anchors.top: employeeHeader.bottom anchors.bottom: parent.bottom anchors.horizontalCenter: parent.horizontalCenter width: parent.width Rectangle { id: clip_container_bg anchors.fill: parent border.color: "black" } ListView { id:clipList anchors.fill: parent model: clip_model delegate: clipDelegate onModelChanged: { console.debug(clip_model); } } } } }
}
@If I change the GridView.qml to
@
import "../elements/"
@I get an Error like
@views/GridView.qml:19: ReferenceError: EmployeeDelegate is not defined@How am I supposed to set Delegates to a List view that are defines in a qml file ?
-
solution 1.
put your qml files into Qt resource system.
solution 2
copy your qml files to the folder in which your program is executed.