类型错误:无法读取 qml 中未定义的属性'days'



下面是我得到上面错误的代码片段。days为嵌套模型:

ApplicationWindow {
id:appWindow
width: 1000
height: 600
visible:true
flags:Qt.FramelessWindowHint
//color: "transparent"
property var monthName:0
property string notesText: monthlistModel.get(monthofdayCalendar.currentIndex).days.get(newdayCalendar.currentIndex).hours.get(dayList.currentIndex).notes
Settings {
property alias notesText: appWindow.notesText
}

下面是listmodel嵌套模型:

ListModel{
id:monthlistModel
Component.onCompleted: {
let months = [
{
monthName: 0,
days: createDays(31) 
},
{
monthName: 1,
days: createDays(29)
},
{
monthName:2,
days: createDays(31)
},
{
monthName: 3,
days: createDays(30)
},
{
monthName:4,
days: createDays(31)
},
{
monthName: 5,
days: createDays(30)
},
{
monthName: 6,
days: createDays(31)
},
{
monthName: 7,
days: createDays(31)
},
{
monthName:8,
days: createDays(30)
},
{
monthName: 9,
days: createDays(31)
},
{
monthName: 10,
days: createDays(30)
},
{
monthName: 11,
days: createDays(31)
}
]
append(months)
}
function createDays(dayCount) {
let days = []
for (let i = 0; i < dayCount+1; i++) {
days.push({
day: i ,
hours: createHours()
}
)
}
return days
}
function createHours() {
let hours = []
for (let i = 0; i < 25; i++) {
hours.push({
hour: i,
notes: ""
}
)
}
return hours
}
}

应用程序代码在下面链接

https://gist.github.com/cgiannakidis70/a5f0f73440013424fc0dedd7e3300f75

如何解决上述错误?

提前感谢。

这通常是非常需要重构的。

撇开这一点不谈,你的ListModel应该包含listelement,而不是javascript对象和嵌套数组。可能值得仔细阅读一下ListModel文档。这里有一个有点相关的问题可以帮助你更多一点。

相关内容

  • 没有找到相关文章

最新更新