首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >QML进度条不移动

QML进度条不移动
EN

Stack Overflow用户
提问于 2020-11-28 14:17:53
回答 1查看 799关注 0票数 0

我正在使用Qtv5.12.6,在我的应用程序中,我计划在应用程序启动时使用进度条,时间大约为15秒。在这15秒的操作中,例如:

带有服务器的creation.

  • connection
  1. QML组件.
  2. 其他启动操作将在后台运行.

一旦所有启动操作完成,我将隐藏我的启动屏幕,它只是一个矩形,其中包括加载带有进度条的文本。对于这15秒,我将增加进度条,但是进度条不会增加/移动大约10秒。它看起来像是挂起来的,但是如果我用一个繁忙的指示器,它就开始旋转。不幸的是,我不能使用繁忙的指示器组件,因为我需要一个外观和感觉像一个进度条。

我的应用程序运行在一个嵌入式平台上,它具有低端处理器和极低的RAM速度。我假设这个问题是由于UI上的负载造成的,因为很多组件正在被创建。

忙碌指示器和进度栏之间有什么不同,以及如何在启动时处理UI负载的建议?

编辑1:添加了一个示例。我已经尽力模仿这个问题了。在本例中,忙碌指示器和进度条都被卡住了一段时间。但是在嵌入式设备中,繁忙的指示器工作起来却不知道是怎么回事。运行应用程序后,请单击,单击Me按钮。

代码语言:javascript
运行
复制
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"
        }
    }
}
EN

回答 1

Stack Overflow用户

发布于 2020-11-29 02:53:44

将您的对象创建代码移动到一个单独的计时器中,间隔很小,而不是一次创建所有对象,而是每25 MS或更多的时间创建它们。

这将允许主事件循环在加载时处理其他事情,如繁忙指示符的动画。

以下是实现这一目标的一个方法

代码语言:javascript
运行
复制
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"
        }
    }
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65050562

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档