Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Can't use int variable in button textbox



  • So, I'm trying to make an app in which if I push a button, the number on it will increase by one. I tried doing it by declaring a universal int variable(Num), and onClicked: Num++;. But I found no way to display that variable in text:...
    I don't have the faintest idea how to do it.

    Any help would be appreciated!



  • Thought I'd just post this as well

    Button {
            id: button
            x: 110
            y: 220
            width: 375
            height: 180
            text: 
            font.pointSize: 30
            scale: 0.4
            anchors.verticalCenter: parent.verticalCenter
            anchors.horizontalCenter: parent.horizontalCenter
            onClicked: Num++;
        }
    

    Also the button is from QtQuick - Controls 2.



  • @tEdward hi

    Window {
        width: 800
        height: 600
        visible: true
        
        property int num : 0
    
        Button {
                id: button
                text: num //<
                onClicked: num++
            }
    }
    

Log in to reply