下拉屏幕以刷新qml中的数据

下拉屏幕以刷新qml中的数据,qml,click,buttonclick,Qml,Click,Buttonclick,在我的应用程序中,我需要应用一个功能,比如当我下拉屏幕时,当前页面就会刷新。为此我做了这件事 示例代码 Page { height: 460 width: 300 id: app property var refreshFlik: "" Flickable { id:flick anchors.fill: parent contentHeight : rect.height Rectangle{ id:rect

在我的应用程序中,我需要应用一个功能,比如当我下拉屏幕时,当前页面就会刷新。为此我做了这件事

示例代码

      Page {
height: 460
width: 300
id: app
property var refreshFlik: ""
Flickable {
    id:flick
    anchors.fill: parent
    contentHeight : rect.height
    Rectangle{
        id:rect
      color: "#fffff1"
        height: 540
        width: 300
    Text{
        id:text
       anchors.centerIn: parent
        text:"Hello World"
    }
    }
    onFlickStarted: {
         refreshFlik = atYBeginning
        busy.running=true
     }
    onFlickEnded: {
         if ( atYBeginning && refreshFlik )
         {
          //   updateDataFromServer();   // it's a function to update the data from server
             console.log("After getting the updated data refresh the page");
             // here after getting the data from server I need to refresh the whole page 
             busy.running=false
         }
     }
}
BusyIndicator{
        id:busy
        anchors.centerIn: parent
        running: false
    }
}

所以这段代码运行得很好,但是我缺少的一点是无法刷新屏幕上的数据。假设屏幕上显示“Hello world”,但从服务器获取数据后,我将屏幕拉下来,文本会根据从服务器获取的数据更改为其他内容。

如果您想重新加载整个内容,我认为最好使用以下组件和加载程序

   Window {
    visible: true
    width: 640
    height: 480
    title: qsTr("Hello World")




    Component{
        id:toLoad
        Page {

            height: 460
            width: 300
            id: app
            signal reloadComponent()
            property var refreshFlik: ""

            Flickable {
                id:flick
                anchors.fill: parent
                contentHeight : rect.height
                Rectangle{
                    id:rect
                    color: "#55ff00ff"
                    height: 540
                    width: 300
                    Text{
                        id:text
                        anchors.centerIn: parent
                        text:"Hello World"
                    }
                }
                onFlickStarted: {
                    refreshFlik = atYBeginning
                    busy.running=true
                }
                onFlickEnded: {
                    if ( atYBeginning && refreshFlik )
                    {
                        //   updateDataFromServer();   // it's a function to update the data from server
                        console.log("After getting the updated data refresh the page");
                        // here after getting the data from server I need to refresh the whole page
                        busy.running=false
                    }
                    reloadComponent()
                }
            }
            BusyIndicator{
                id:busy
                anchors.centerIn: parent
                running: false
            }


            Component.onCompleted:{
                console.log("loaded")
            }
        }

    }



    Loader{
        id:ldr
        sourceComponent: toLoad

        Connections{
            target:ldr.item
            onReloadComponent:{
                console.log("reloading")
                ldr.sourceComponent=undefined
                ldr.sourceComponent=toLoad
            }
        }


    }


}

你的问题完全不清楚。您提供的代码也是如此。请提供并澄清问题。加载到什么?你的问题不清楚你在说什么。在此上下文中,
当前页面是什么?因此,请回顾一下你的问题,然后发布,我想你会得到一个解决问题的答案。要了解如何“重新加载”你的UI,我们需要了解它最初是如何加载的。我已经编辑了整个问题。现在它可能更有意义了。很抱歉没有提供细节。请帮帮我,它没用。为什么将加载程序保留在组件外部?您到底要加载什么?是文本还是要加载整个qml组件?整个组件要加载整个组件,您需要在组件外部加载程序。Loader是重新加载组件的人。这就是它位于组件外部的原因