1

I have a QML object as follows:

// File: ControlView.qml
Rectangle {
    id: view
    property bool darkBackground: false

    Text {
        id: textSingleton
    }

    SoundEffect {
        id: playCalSound
        source: "qrc:/sound/calender_time_camera.wav"
    }
}

I have another control that is contained within it and my issue is that I cannot access the playCalSound or textSingleton elements.

// File: MyControl.qml
ControlView {
   ....
   playCalSound.play() // playCalSound is not defined
   textSingleton.font.pixelSize // textSingleton is not defined

   view.textSingleton // view is not defined
}
4

1 回答 1

3

You should define properties for objects you want use outside file. Try this

Rectangle {
    id: view
    property bool darkBackground: false
    property var effect: playCalSound
    property alias singletext: textSingletone.text

    Text {
        id: textSingleton
    }

    SoundEffect {
        id: playCalSound
        source: "qrc:/sound/calender_time_camera.wav"
    }
}

..............


ControlView {
   ....
   Component.onComplited: effect.play()

   singletext: 'some text'
}
于 2016-02-01T08:54:49.207 回答