This error occurs every time I run the below code in qmlscene .In the code there 3 nested ListView
s which are populated dynamically with ListModel
s.
The inside ListView
is called daylistView , the outer dayCalendar and the third monthofdayCalendar. Each of them represents the hour of the day, the day and the month accordingly.There is a MouseArea
where when I click, opens a window so I can set the text of a Label
for a specific hour.
When I run the code and click in the mouse area, the window is opened to set the label text and the above error is displayed.But if I change the displayed day for 2 or 3 times continually then the code is running without error until I choose a day from another month. Following the same method the error stops being displayed after I change the day for 2 or 3 times manually.
How can I solve this issue because every time this error is displayed I can not set the text in the Label
notesLabel.
Below is the code with some deductions so is more compact:
ListView{
id: monthofdayCalendar
width: dayView.width*.58
height: dayView.height-100
x:10
y:20
interactive: false
highlightRangeMode: ListView.StrictlyEnforceRange
boundsBehavior:Flickable.StopAtBounds
orientation: Qt.Horizontal
clip: true
model:monthlistModel//12
currentIndex : calendarMonth.selectedDate.getMonth()
highlightMoveDuration : 200
highlightMoveVelocity : 1000
delegate: Item {
width:monthofdayCalendar.width
height:monthofdayCalendar.height
property int monthofdaycalendarIndex: index
property var newdayCalendar: dayCalendar
Label {
id: monthnameLabel
x:400
y:20
text:Qt.locale("en_US").standaloneMonthName((monthName===calendarMonth.selectedDate.getMonth() ? monthName : calendarMonth.selectedDate.getMonth()), Locale.LongFormat) calendarMonth.selectedDate.toLocaleDateString(Qt.locale("en_US"), " yyyy")//calendarMonth.selectedDate.getFullYear(),index,calendarMonth.selectedDate.getDate() ).getMonth()index
font.pointSize: 18
}
ListView {
id:dayCalendar
x: 0
y: 50
width: monthofdayCalendar.width
height: monthofdayCalendar.height
interactive: false
highlightRangeMode: ListView.StrictlyEnforceRange
boundsBehavior:Flickable.StopAtBounds
orientation: Qt.Horizontal
clip: true
currentIndex : calendarMonth.selectedDate.getDate()
model:daylistModel//32
highlightMoveDuration : 500
highlightMoveVelocity : 1000
delegate : Item{
id:calDelegate
width: dayCalendar.width
height: dayCalendar.height
property int calIndex: index
property var dayList: daylistView
Row {
id: eventDateRow
width: parent.width
height: eventDayLabel.height
spacing: 10
Label {
id: eventDayLabel
text: day===0 ? calendarMonth.selectedDate.getDate() : day
font.pointSize: 35
}
Column {
height: eventDayLabel.height
Label {
text:Qt.locale("en_US").standaloneDayName((new Date(calendarMonth.selectedDate.getFullYear(),calendarMonth.selectedDate.getMonth(),(day===0 ? calendarMonth.selectedDate.getDate() : day))).getDay(), Locale.LongFormat) //Qt.locale("en_US").standaloneDayName(calendarMonth.selectedDate.getDay(), Locale.LongFormat)
font.pointSize: 14
}
/* Label {
text: Qt.locale("en_US").standaloneMonthName(calendarMonth.selectedDate.getMonth())
calendarMonth.selectedDate.toLocaleDateString(Qt.locale("en_US"), " yyyy")
font.pointSize: 12
}*/
}
}
ListView{
id:daylistView
width:dayCalendar.width
height:dayCalendar.height - 60
boundsBehavior:Flickable.StopAtBounds
highlightRangeMode: ListView.ApplyRange//StrictlyEnforceRange
orientation: Qt.Vertical
anchors.top:eventDateRow.bottom
clip:true
focus:true
model:hourlistModel
currentIndex : calendarMonth.selectedDate.getDay() === new Date().getDay()
&& calendarMonth.selectedDate.getDate() === new Date().getDate()
&& calendarMonth.selectedDate.getMonth() === new Date().getMonth() ? getHour() : 12
interactive: true
delegate: Item{
id:hourItem
property var hourTime: hourweeklistviewLabel
property var notetaking: notesLabel
width: daylistView.width
height: 60
MouseArea{
anchors.fill:parent
onClicked:{
windowLoader.active =true
daylistView.currentIndex=index
//dayCalendar.currentIndex = calDelegate.calIndex
//dayCalendar.currentIndex = Qt.binding(function() { return calendarMonth.selectedDate.getDate() })
}
}
Rectangle {
z:4
id:hourdaylistviewindexLine
y:getdayMinute()
width:hourItem.width
height:2
border.color: calendarMonth.selectedDate.getDate()===new Date().getDate()
&& getHour() ":00" === hourweeklistviewLabel.text
&& calendarMonth.selectedDate.getMonth() === new Date().getMonth()
?"red" : "transparent"
border.width:1
}
Rectangle {
z:4
id:hourline
anchors.verticalCenter: daylistView
width:daylistView.width
height:2
border.color: getHour() ":00" === hourweeklistviewLabel.text
&& calendarMonth.selectedDate.getDate()===new Date().getDate()
&& calendarMonth.selectedDate.getMonth() === new Date().getMonth()
&& getdayMinute()=== "00" ? "red": "lightgray"
border.width:1
}
Label{
z:4
id:hourweeklistviewLabel
anchors.verticalCenter: parent
text: hour ":00"
color: getHour() ":00" === hourweeklistviewLabel.text
&& calendarMonth.selectedDate.getDate() === new Date().getDate()
&& calendarMonth.selectedDate.getDay() === new Date().getDay()
&& calendarMonth.selectedDate.getMonth() === new Date().getMonth()
? systemPalette.highlight : "lightgray"
font.pointSize: 10
}
Label{
z:4
id:notesLabel
anchors.left:hourweeklistviewLabel.right
anchors.leftMargin: 30
text:""
}
}
}
ListModel{
id:hourlistModel
Component.onCompleted:{
for (var i = 0; i <=24; i ){
append(createListElement())
}
}
property int h:0
function createListElement(){
return {
hour : h
}
}
}
}
}
ListModel{
id:daylistModel
Component.onCompleted:{
for (var j=0; j <= 31; j ){
append(createListElement())
}
}
property int dD:0
function createListElement(){
return {
day : dD
}
}
}
}
}
ListModel{
id:monthlistModel
Component.onCompleted:{
for (var k=0; k <=11; k ){
append(createListElement())
}
}
property int mN:0
function createListElement(){
return {
monthName : mN
}
}
}
}
CodePudding user response:
After a lot of research and time, the solution was just to set as currentIndex
in monthofdayCalendar ListView
, the property monthName and not the calendarMonth.selectedDate.getMonth().Now the code runs without errors.