1

TabView を使用する QT Quick プログラムを作成しました。Tabview にあるボタン b1 をクリックすると、プログラムは show_text() を呼び出して b1 のテキストを出力する必要がありますが、「ReferenceError: b1 が定義されていません」と出力されます。任意の提案をいただければ幸いです。

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()
                }
            }
        }
    }
}
4

2 に答える 2

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()
            }
        }
    }
}

}

于 2014-02-21T11:22:39.573 に答える