Important: Please read the Qt Code of Conduct -

Dynamic created buttons change content of other dynamic created elements

  • Hello

    With the help of the forum I dynamically created some buttons which I assigned a function to a property..
    Now, inside this function, I would like to refer to other Items which are also dynamically created.

    The (pseudo)code currently looks something like this:

    property var money_back: { '50e': 0,
    '20e': 0,
    '10e': 0,
    '5e': 0,
    '2e': 0,
    '1e': 0,
    '50c': 0,
    '20c': 0,
    '10c': 0,
    '5c': 0,
    '2c': 0,
    '1c': 0 };
    spacing: 5

        Component.onCompleted: {
            var button = Qt.createComponent("BubbleButton.qml");
            var selected = Qt.createComponent("ChangeText.qml");
            for (var prop in change_screen.money_back){
                                          "id": "selected_"+prop,
                                          "selected": "0"
                                                "id": "button_"+prop,
                                                "action": [function(){ selected_50e.selected += 1; }],
                                                //"ps": ps,
                                                "img_id.source": prop+".png",
                                                "img_id.align": "center",
                                                "color": "transparent"

    What I want to do in the end is the following: create Buttons for each coin/note and when clicked on, I want to change the content of the Text.. like a counter, how many times I clicked on a Button.

    Is there an easier way than going down the road with signals and such? (looks complicated)

    thank you for your time and help

Log in to reply