Re: [Qt-qml] Error with PropertyAction/SequentialAnimation/Timer
Thanks, That works! The behaviour does seem slightly strange though - I would expect the JS function to complete and THEN have everything else updated, but as long as I know that this is the current behaviour I can create code accordingly. Thanks again Mark -Original Message- From: Adriano Rezende [mailto:adriano.reze...@openbossa.org] Sent: 07 December 2010 19:16 To: Mark Tucker Cc: qt-qml@trolltech.com Subject: Re: [Qt-qml] Error with PropertyAction/SequentialAnimation/Timer On Tue, Dec 7, 2010 at 12:59 PM, Mark Tucker mark.tuc...@airborne.aero wrote: Timer { id: textTimer interval: 5000 repeat: true running: true triggeredOnStart: true onTriggered: { listIndex++; if (listIndex = model.count) { listIndex = 0; } //console.log(listIndex: + listIndex + count: + model.count) textAnimation.start(); } } } For some reason the PropertyAction is being called when listIndex is 3 and hence causes an error due to an undefined value. I'm failing to see how it should ever be the case that listIndex should be 3 when the PropertyAction does its thing though. I believe QML will reevaluate a JS statement each time you change a bindable property contained in that statement. So, even if the animation is not running, model.get(listIndex).dataString will be reevaluated when listIndex changes. So, in order to solve this problem you can change the code below: listIndex++; if (listIndex = model.count) { listIndex = 0; } for the following: listIndex = (listIndex + 1) % model.count; Br, Adriano ___ Qt-qml mailing list Qt-qml@trolltech.com http://lists.trolltech.com/mailman/listinfo/qt-qml
[Qt-qml] Error with PropertyAction/SequentialAnimation/Timer
Hello, I am trying to animate changing a string, by fading it out, changing it, then fading it back in, but I'm having an issue with the way I am populating the string, and I have no idea why. The following is an example as simplified as I can get it that exhibits this error: //ListIndexError.qml import Qt 4.7 Rectangle { width: 200 height: 200 property int listIndex: 0 ListModel { id: model ListElement{ dataString: String 1 } ListElement{ dataString: String 2 } ListElement{ dataString: String 3 } } Text { id: textArea anchors.centerIn: parent } SequentialAnimation { id: textAnimation //alwaysRunToEnd: true NumberAnimation { target: textArea; property: opacity; to: 0; duration: 250 } PropertyAction { target: textArea; property: text; value: { /*console.log(In PropertyAction + listIndex: + listIndex + count: + model.count);*/ model.get(listIndex).dataString } } NumberAnimation { target: textArea; property: opacity; to: 1; duration: 250 } } Timer { id: textTimer interval: 5000 repeat: true running: true triggeredOnStart: true onTriggered: { listIndex++; if (listIndex = model.count) { listIndex = 0; } //console.log(listIndex: + listIndex + count: + model.count) textAnimation.start(); } } } I've commented out the two console.log entries above, which I am using to try and figure out what is going on. Note that the behaviour observed is the same with Qt 4.7.0 or 4.7.1. The Timer fires every 5 seconds and in doing so increments the listIndex property. It then checks to make sure that it is still valid by checking it against model.count, if it's equal to or greater then that then it resets it to 0. After that, still in the onTriggered handler, it then starts the animation. For some reason the PropertyAction is being called when listIndex is 3 and hence causes an error due to an undefined value. I'm failing to see how it should ever be the case that listIndex should be 3 when the PropertyAction does its thing though. Am I missing something blatantly obvious here or is there a but in Qt somewhere here? Thanks Mark Tucker ___ Qt-qml mailing list Qt-qml@trolltech.com http://lists.trolltech.com/mailman/listinfo/qt-qml
Re: [Qt-qml] Error with PropertyAction/SequentialAnimation/Timer
On Tue, Dec 7, 2010 at 12:59 PM, Mark Tucker mark.tuc...@airborne.aero wrote: Timer { id: textTimer interval: 5000 repeat: true running: true triggeredOnStart: true onTriggered: { listIndex++; if (listIndex = model.count) { listIndex = 0; } //console.log(listIndex: + listIndex + count: + model.count) textAnimation.start(); } } } For some reason the PropertyAction is being called when listIndex is 3 and hence causes an error due to an undefined value. I'm failing to see how it should ever be the case that listIndex should be 3 when the PropertyAction does its thing though. I believe QML will reevaluate a JS statement each time you change a bindable property contained in that statement. So, even if the animation is not running, model.get(listIndex).dataString will be reevaluated when listIndex changes. So, in order to solve this problem you can change the code below: listIndex++; if (listIndex = model.count) { listIndex = 0; } for the following: listIndex = (listIndex + 1) % model.count; Br, Adriano ___ Qt-qml mailing list Qt-qml@trolltech.com http://lists.trolltech.com/mailman/listinfo/qt-qml