Problem z Component rozwiazany. Okazalo sie, ze component moze zawierac w sobie tylko id i dodatkowy element, czyli w sumie dwa elementy. Wystarczylo wywalic Drugi element Text z Component i poszlo.
https://doc.qt.io/qt-5/qml-qtqml-component.html
a Component definition contains a single top level item (which in the above example is a Rectangle) and cannot define any data outside of this item, with the exception of an id (which in the above example is redSquare).
Kopiuj
import QtQuick.Window 2.15
import QtQuick.Controls 1.4
import QtQuick.Layouts 1.15
import QtQuick 2.15
import QtQml 2.15
//import QtQuick 2.0
Window
{
id: alarmListWindow
width: 400
height: 400
ListModel
{
id: modelID
ListElement {
name: "Bill Smith"
number: "555 3264"
}
ListElement {
name: "John Brown"
number: "555 8426"
}
ListElement {
name: "Sam Wise"
number: "555 0473"
}
}
Component
{
id: delegatID
Text
{
id: name
text: "Name: " + model.name + " : Number: " + model.number
}
}
ListView
{
id: listviewID
anchors.fill: parent
width: 180; height: 200
model: modelID
delegate: delegatID
}
}
Plik powyzej nazywa sie "alarm_list_window.qml"
Chcac go wywolac, nalezy dodac takie cos w pliku z ktorego chce sie go wywolac
Kopiuj
property var component_alarm_list: Qt.createComponent("alarm_list_window.qml")
property var alarm_list_object: component_alarm_list.createObject(mainWindow)
alarm_list_object.visible = true
Wyglada na to, ze ListView, to tak naprawde kontener w srodku ktorego sa odwolania do danych ktore ma wyswietlic (uzywa sie obiektow "model". W tym przypadku, obiekt ten ma id modelID) i formatowania, czyli obiektow delegate. Ww tym przypadku, jest to obiekt o id delegatID.