Error: Cannot assign JavaScript function to QString



  • @Rectangle {
    id: confirmButton
    visible: false
    width: 100
    height: 50
    x:100
    y:225
    color: "black"
    border.color:"white"

                MouseArea {
                    id: confirmButtonText
                    anchors.fill: parent
    
                    function addStrings(calcInput1, calcInput2)
                                        {
                                            var Sum=pasteInt(calcInput1)+parseInt(calcInput2)
                                            return Sum
                                        }
    
                    onClicked: result.text = addStrings
                }
                Text {
                    
                    anchors.centerIn: parent
                    text: "confirm"
                    color: "white"
                }
            }
    

    @

    Im very new to QML and QT and I was wondering if anyone could help me with parsing to a Qstring? Thanks

    [edit: added missing coding tags @ SGaist]


  • Lifetime Qt Champion

    Hi,

    You can't assign a JavaScript function to a QString however you can put the result of the function in it.

    Here's a version of your code working

    @
    Rectangle {
    id: confirmButton
    width: 100
    height: 50
    color: "black"
    border.color:"white"

    MouseArea {
        id: confirmButtonText
        anchors.fill: parent
    
        function addStrings(calcInput1, calcInput2)
        {
            var Sum=parseInt(calcInput1)+parseInt(calcInput2)
            return Sum
        }
    
        onClicked: result.text = addStrings(2, 3)
    }
    Text {
        id: result
        anchors.centerIn: parent
        text: "confirm"
        color: "white"
    }
    

    }@


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.