当长时间的进程在运行时,我想展示一个BusyIndicator
。问题是,在我让它运行时它并没有显示出来,而是在进程完成后才显示。根据文档:
当内容正在加载或UI正在等待资源变得可用时,应使用忙指示器来指示活动。
我已经创建了一个基于原始代码的最小代码。
Window {
id: win
width: 300
height: 300
property bool run : false
Rectangle {
anchors.fill: parent
BusyIndicator {
anchors.centerIn: parent
running: run
}
MouseArea {
anchors.fill: parent
onClicked: {
run = true
for(var a=0;a<1000000;a++) { console.log(a) }
run = false
}
}
}
}
当单击
Rectangle
时,我希望在计算完成之前显示BusyIndicator
。例如,这里使用了for循环以示例为目的。在实际场景中,我通过
ContextProperty
调用一个函数(将大约1000行插入到数据库中)。但即使是这种情况下,BusyIndicator
也不会显示。我这样做对吗?或者有更好的方法吗?
WorkerScript
。 - folibis