0

I am implemeting Multiple add button programmatically. I sucessfully add button but I can't able get click event for all button. I am always getting click on last added button.

I want separately click event for all button.

I am using this code for add button.

ComponentDefinition {
            id: mComponentDefinitionSubmitButton
            Button {
                id: mButtonID
                horizontalAlignment: HorizontalAlignment.Center
                onClicked: {
                    //My Click code. Always detect last button.
                }
            }
        }

var mButton = mComponentDefinitionSubmitButton.createObject();
mButton.text = qsTr(title)
mContainerButton.add(mButton)
Niranj Patel
  • 32,980
  • 10
  • 97
  • 133

1 Answers1

3

I done with signal..

function checkClick(button)
    {
        console.debug("click..."+ button);
    }
    attachedObjects: [
        ComponentDefinition {
            id: mComponentDefinitionSubmitButton

            Button {
                id: mButtonID
                signal click(variant text);
                horizontalAlignment: HorizontalAlignment.Center
                onClicked: {
                    click(mButtonID.text);
                }
            }
        }
    ]

----------------------------------------------------------------
var mButton = mComponentDefinitionSubmitButton.createObject();
mButton.text = qsTr("Button");
mButton.click.connect(checkClick);
btnContainer.add(mButton);
Niranj Patel
  • 32,980
  • 10
  • 97
  • 133