2013-08-16 4 views
0

프로그래밍 방식으로 여러 추가 버튼을 구현하고 있습니다. 성공적으로 버튼을 추가했지만 모든 버튼에 대해 클릭 이벤트를 가져올 수 없습니다. 마지막으로 추가 된 버튼을 항상 클릭하고 있습니다.클릭 이벤트가있는 동적 버튼 추가

모든 버튼에 대해 별도로 이벤트를 클릭하고 싶습니다.

추가 버튼에이 코드를 사용하고 있습니다. I 신호로 이루어

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) 

답변

3

..

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);