PDA

View Full Version : How to use a script for a value property with QtQuick1 ?



djszapi
7th February 2012, 07:03
Hi,

What is the best approach to work around the QtQuick1 limitations for this ?

ListElement: cannot use script for property value
remainingTimeElementRole: (function () { return (countDownTimerValue / 60 / 10).toFixed(0); }) ();

I began without a closure, and then I had that idea to try out, but apparently no go. :(

Here is the ListModel code:

ListModel {
id: remainingTimeModel;
ListElement {
remainingTimeElementRole: (countDownTimerValue / 60 / 10).toFixed(0);
}

ListElement {
remainingTimeElementRole: countDownTimerValue / 60 % 10;
}

ListElement {
remainingTimeElementRole: ":";
}

ListElement {
remainingTimeElementRole: (countDownTimerValue % 60 / 10).toFixed(0);
}

ListElement {
remainingTimeElementRole: countTimerDownTimerValue % 60 % 10;
}
}

Thank you in advance!

Added after 11 minutes:

Probably for loop in a Component.onCompleted block inside the ListModel, and call ListModel append() with the appropriate values is the simplest hack around. :/

wysota
8th February 2012, 02:13
Define the function not as a lambda function but as a regular one and call it normally.

ListModel {

function remainingTime(val) { return (val / 60 / 10).toFixed(0); }

ListElement { remainingTimeElementRole: remainingTime(val); }
}