Problems with Open-Source Downloads read and

Problem with SpinBox and double values in QML

  • Hello,
    I'm working on a QML project. I have a problem with double values in my QML. I expose a C++ variable to my QML.

                                                    minimumValue:  0
                                                    maximumValue: 10000
                                                    decimals: 2
                                                    onValueChanged:  {
                                                        console.log("value added")

    I set the value to 9.18 however it takes the value 9.
    Can anyone help?

  • Lifetime Qt Champion

    @Babs SpinBox is for integers, not floating point numbers. But you can use floating point numbers as shown in the documentation:

    In the same manner, SpinBox can be customized to accept floating point numbers:
    SpinBox {
        id: spinbox
        from: 0
        value: 110
        to: 100 * 100
        stepSize: 100
        anchors.centerIn: parent
        property int decimals: 2
        property real realValue: value / 100
        validator: DoubleValidator {
            bottom: Math.min(spinbox.from,
            top:  Math.max(spinbox.from,
        textFromValue: function(value, locale) {
            return Number(value / 100).toLocaleString(locale, 'f', spinbox.decimals)
        valueFromText: function(text, locale) {
            return Number.fromLocaleString(locale, text) * 100

Log in to reply