現在,有一個用于激活該功能的按鈕,例如:
Window {
id: window
width: Screen.width
height: Screen.height
visible: true
property alias originalImage: originalImage
title: qsTr("Window1")
Button{
id: startButton
x: 50
y:100
text: "Open"
onClicked: {
VideoStreamer.openVideoCamera()
}
}
但我想激活此方法just after the window is created,而不是單擊按鈕。喜歡
Window {
id: window
width: Screen.width
height: Screen.height
visible: true
property alias originalImage: originalImage
title: qsTr("Window1")
VideoStreamer.openVideoCamera()
}
但它不是那樣作業的。我得到expected token ":" 錯誤。它期望類似somecondition:如何在沒有按鈕或沒有外部用戶需要的條件(如onclicked:等)的情況下進行管理?
uj5u.com熱心網友回復:
您可以使用Component.onCompleted信號在組件創建后立即執行操作。
onCompleted 信號處理程式可以在任何物件上宣告。運行處理程式的順序是未定義的。
Window {
id: window
width: Screen.width
height: Screen.height
visible: true
property alias originalImage: originalImage
title: qsTr("Window1")
Component.onCompleted:
{
VideoStreamer.openVideoCamera()
}
}
PS:如果你的 VideoStreamer 是一個 QML 物件,那么直接在那里使用這個信號會更好。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/361435.html
上一篇:委托中的動態屬性名稱分配
