summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2017-03-16 16:11:45 +0100
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2017-03-20 08:57:28 +0000
commit71cd0a58c025a1019b62bc3a6d4514ea677185b8 (patch)
tree7ff7b8fd7a77d231d997412d26e8314da68f39c0 /examples
parent7a125135e1ef592aa20a29f7aac1a6117a6b1770 (diff)
stocqt Demo: Add error checks
Check for corrupted records, fixing warnings: qrc:///demos/stocqt/content/StockListModel.qml:90: TypeError: Cannot call method 'split' of undefined Also check the value and prevent NaN from appearing. Change-Id: I3a9d010c61fb0f017aef37df7f54a7ad4d7d7d53 Reviewed-by: Venugopal Shivashankar <Venugopal.Shivashankar@qt.io>
Diffstat (limited to 'examples')
-rw-r--r--examples/quick/demos/stocqt/content/StockListModel.qml35
1 files changed, 18 insertions, 17 deletions
diff --git a/examples/quick/demos/stocqt/content/StockListModel.qml b/examples/quick/demos/stocqt/content/StockListModel.qml
index 9b48124bda..02ece32a49 100644
--- a/examples/quick/demos/stocqt/content/StockListModel.qml
+++ b/examples/quick/demos/stocqt/content/StockListModel.qml
@@ -82,27 +82,28 @@ ListModel {
xhr.onreadystatechange = function() {
if (xhr.readyState === XMLHttpRequest.LOADING || xhr.readyState === XMLHttpRequest.DONE) {
var records = xhr.responseText.split('\n');
+ var unknown = "n/a";
+ set(index, {"value": unknown, "change": unknown, "changePercentage": unknown});
if (records.length > 0 && xhr.status == 200) {
var r = records[1].split(',');
var today = parseFloat(r[4]);
- setProperty(index, "value", today.toFixed(2));
+ if (!isNaN(today))
+ setProperty(index, "value", today.toFixed(2));
+ if (records.length > 2) {
+ r = records[2].split(',');
+ var yesterday = parseFloat(r[4]);
+ var change = today - yesterday;
+ if (change >= 0.0)
+ setProperty(index, "change", "+" + change.toFixed(2));
+ else
+ setProperty(index, "change", change.toFixed(2));
- r = records[2].split(',');
- var yesterday = parseFloat(r[4]);
- var change = today - yesterday;
- if (change >= 0.0)
- setProperty(index, "change", "+" + change.toFixed(2));
- else
- setProperty(index, "change", change.toFixed(2));
-
- var changePercentage = (change / yesterday) * 100.0;
- if (changePercentage >= 0.0)
- setProperty(index, "changePercentage", "+" + changePercentage.toFixed(2) + "%");
- else
- setProperty(index, "changePercentage", changePercentage.toFixed(2) + "%");
- } else {
- var unknown = "n/a";
- set(index, {"value": unknown, "change": unknown, "changePercentage": unknown});
+ var changePercentage = (change / yesterday) * 100.0;
+ if (changePercentage >= 0.0)
+ setProperty(index, "changePercentage", "+" + changePercentage.toFixed(2) + "%");
+ else
+ setProperty(index, "changePercentage", changePercentage.toFixed(2) + "%");
+ }
}
}
}