我正在使用Qtv5.12.6,在我的应用程序中,我计划在应用程序启动时使用进度条,时间大约为15秒。在这15秒的操作中,例如:
带有服务器的creation.
一旦所有启动操作完成,我将隐藏我的启动屏幕,它只是一个矩形,其中包括加载带有进度条的文本。对于这15秒,我将增加进度条,但是进度条不会增加/移动大约10秒。它看起来像是挂起来的,但是如果我用一个繁忙的指示器,它就开始旋转。不幸的是,我不能使用繁忙的指示器组件,因为我需要一个外观和感觉像一个进度条。
我的应用程序运行在一个嵌入式平台上,它具有低端处理器和极低的RAM速度。我假设这个问题是由于UI上的负载造成的,因为很多组件正在被创建。
忙碌指示器和进度栏之间有什么不同,以及如何在启动时处理UI负载的建议?
编辑1:添加了一个示例。我已经尽力模仿这个问题了。在本例中,忙碌指示器和进度条都被卡住了一段时间。但是在嵌入式设备中,繁忙的指示器工作起来却不知道是怎么回事。运行应用程序后,请单击,单击Me按钮。
import QtQuick 2.12
import QtQuick.Window 2.12
import QtQuick.Controls 2.3
Window {
property int pbValue:0
visible: true
width: 500
height: 400
title: qsTr("Hello World")
Rectangle{
id: mySplashScreen
anchors.fill: parent
ProgressBar{
id: pBar
height: 20
width: parent.width
anchors.bottom: parent.bottom
from:0
value : pbValue
to:30
}
BusyIndicator{
anchors.right: parent.right
running: (pbValue < pBar.to +1)
}
Button{
text: "click me"
onClicked: {
//Create component equivalent to my application which has "n"
//number of components like buttons, combobox, chart view etc.
//Here just creating the rectangle more number of times.
for(var i = 0 ; i < 15000 ;i++) //HINT : Increase/decrease the value if problem is not seen
{
var comp = mycomp.createObject(mySplashScreen)
}
}
}
}
Timer{
id:timer
interval: 250
running: (pbValue < pBar.to +1)
onTriggered: {
pbValue += 1;
}
}
Component{
id:mycomp
Rectangle{
width: 200
height: 200
color: "green"
}
}
}
发布于 2020-11-29 02:53:44
将您的对象创建代码移动到一个单独的计时器中,间隔很小,而不是一次创建所有对象,而是每25 MS或更多的时间创建它们。
这将允许主事件循环在加载时处理其他事情,如繁忙指示符的动画。
以下是实现这一目标的一个方法
import QtQuick 2.12
import QtQuick.Window 2.12
import QtQuick.Controls 2.3
Window {
property int pbValue: 0
visible: true
width: 500
height: 400
title: qsTr("Hello World")
Rectangle {
id: mySplashScreen
anchors.fill: parent
ProgressBar {
// changed handling of progress bar
id: pBar
height: 20
width: parent.width
anchors.bottom: parent.bottom
from: 0
value: compList.length // bind this value
to: 15000
}
BusyIndicator {
anchors.right: parent.right
running: (pbValue < pBar.to + 1)
}
Button {
text: "click me"
onClicked: {
timer.running = true
}
}
}
property var compList: [] // created property to store all created components to track what has been done
Timer {
id: timer
interval: 25
running: false
repeat: true
onTriggered: {
for (var i = 0; i < 50; i++) {
var comp = mycomp.createObject(mySplashScreen) // moved component into timer
compList.push(comp) // added component to huge list of components for tracking
}
pbValue = compList.length
if ((pbValue >= 15000)) {
timer.running = false
console.log("All components completed")
}
}
}
Component {
id: mycomp
Rectangle {
width: 200
height: 200
color: "green"
}
}
}
https://stackoverflow.com/questions/65050562
复制相似问题