2014-02-21 4 views
1

QT Quick 프로그램을 작성하여 TabView를 사용합니다. Tabview에있는 botton b1을 클릭하면 프로그램은 show_text()를 호출하고 b1의 텍스트를 인쇄해야하지만 "ReferenceError : b1 is not defined"가 인쇄됩니다. 감사의 말을 전하면됩니다.Qt 빠른 제어 탭 뷰의 ReferenceError

import QtQuick 2.2 
import QtQuick.Controls 1.1 
import QtQuick.Window 2.1 



ApplicationWindow { 
    function show_text() { 
     console.log(b1.text) 
    } 

    TabView { 
     id: tv 
     Tab { 
      id: tab1 
      Button{ 
       id: b1 
       text:"b1's text" 
       onClicked: { 
        //console.log(b1.text) 
        show_text() 
       } 
      } 
     } 
    } 
} 

답변

0

이 예에서는 개체에 액세스 할 수 있습니다.

ApplicationWindow { 
function show_text() { 
    console.log(tv.b1Text); 
} 

TabView { 
    id: tv 
    property alias b1Text: b1.text 
    Tab { 
     id: tab1 
     Button{ 
      id: b1 
      text:"b1's text" 
      onClicked: { 
       //console.log(b1.text) 
       show_text() 
      } 
     } 
    } 
} 

}

+1

로 객체를 전달합니다. id "b1"'을 (를) 찾을 수 없습니다. – ony

1

내가`잘못된 별칭 참조를 가져 매개 변수 Qt는 5.7

import QtQuick 2.2 
import QtQuick.Controls 1.1 
import QtQuick.Window 2.1 

ApplicationWindow { 
    function show_text(myobject) { 
     console.log(myobject.text) 
    } 

    TabView { 
     id: tv 
     Tab { 
      id: tab1 
      Button{ 
       id: b1 
       text: "b1's text" 
       onClicked: { 
        show_text(b1) 
       } 
      } 
     } 
    } 
}