summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJens Bache-Wiig <jens.bache-wiig@digia.com>2013-09-10 12:44:35 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-09-10 16:20:24 +0200
commit6bcacdecb8445a5ad9a31f6bdac99cde076e6295 (patch)
tree2abbb1022343dec02663ce1656412ecad383782e
parent5520918af2cfb00618765820df2a28916a12c626 (diff)
downloadqtquickcontrols-6bcacdecb8445a5ad9a31f6bdac99cde076e6295.tar.gz
Fix incorrect spinbox validation at startup
The problem was that the validator was applied during the object creation which means the incorrect decimal values were applied and the initial value was incorrectly changed. Task-number: QTBUG-33309 Change-Id: Ic1ace174b9059b9c6ce24fd88b81c5edd7318e80 Reviewed-by: Caroline Chao <caroline.chao@digia.com> Reviewed-by: J-P Nurmi <jpnurmi@digia.com>
-rw-r--r--src/controls/SpinBox.qml5
-rw-r--r--tests/auto/controls/data/tst_spinbox.qml10
2 files changed, 13 insertions, 2 deletions
diff --git a/src/controls/SpinBox.qml b/src/controls/SpinBox.qml
index b1f87cec..6f62c3a3 100644
--- a/src/controls/SpinBox.qml
+++ b/src/controls/SpinBox.qml
@@ -229,8 +229,9 @@ Control {
validator: SpinBoxValidator {
id: validator
- onTextChanged: input.text = validator.text
- Component.onCompleted: input.text = validator.text
+ property bool ready: false // Delay validation until all properties are ready
+ onTextChanged: if (ready) input.text = validator.text
+ Component.onCompleted: {input.text = validator.text ; ready = true}
}
onAccepted: {
input.text = validator.text
diff --git a/tests/auto/controls/data/tst_spinbox.qml b/tests/auto/controls/data/tst_spinbox.qml
index 267e9c4b..ed39f080 100644
--- a/tests/auto/controls/data/tst_spinbox.qml
+++ b/tests/auto/controls/data/tst_spinbox.qml
@@ -87,6 +87,16 @@ Item {
spinbox.destroy()
}
+ function test_initial_value() {
+ var spinbox = Qt.createQmlObject('import QtQuick.Controls 1.0; SpinBox {decimals: 3 ; value: 0.25}', container, '')
+ compare(spinbox.value, 0.25)
+ spinbox.destroy()
+
+ spinbox = Qt.createQmlObject('import QtQuick.Controls 1.0; SpinBox {value: 0.25 ; decimals: 3}', container, '')
+ compare(spinbox.value, 0.25)
+ spinbox.destroy()
+ }
+
function test_keyboard_input_data() {
return [
{tag: "1", input: [Qt.Key_1], value: 1},