Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Delaying loading object of a loader
Forum Updated to NodeBB v4.3 + New Features

Delaying loading object of a loader

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
5 Posts 5 Posters 416 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    maydin
    wrote on last edited by
    #1

    Title is a bit confusing but if you find a better title feel free to change.

    I have a long operation in a C++ function, lets say 5 seconds, and I want to show a busy indicator until its finished.

    But Loader immediately loads the sourceComponent. I couldn't delay creation of sourceComponent.

    Loader {
    asynchronous: true
    sourceComponent: ColumnLayout {
            property var myModel: Backend.longOperation() //5 seconds
    
            Component.onCompleted: {
                  console.log("ready")
            }
    
            onMyModelChanged: {
                 console.log(JSON.stringify(myModel))
            }
    }
    onStatusChanged: console.log(status)
    }
    

    Output as like this:

    2 // Loader.Loading
    ready
    1 // Loader.Ready
    // after 5 seconds
    [whats inside the object]
    

    It should wait my long operation then status should be ready so I can show a busy indicator.

    By the way, this is how I wait in C++ which might break things:

    QTime dieTime= QTime::currentTime().addSecs(5);
        while (QTime::currentTime() < dieTime)
            QCoreApplication::processEvents(QEventLoop::AllEvents, 100);
    
    small_birdS 1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Qt Champions 2022
      wrote on last edited by
      #2

      How about setting the sourecomponent property value when the task is finished ?

      Dheerendra
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

      1 Reply Last reply
      0
      • K Offline
        K Offline
        kkuzawska
        wrote on last edited by
        #3

        Maybe set Loader visible property according to loader status?

        Loader {
        visible: status===Loader.Ready
        ....
        

        and the same for the animation item (busy indicator) you want to be visible when long operation is in progress

        YourLoadingAnimationItem{
        visible: status===Loader.Loading
        ...
        
        1 Reply Last reply
        0
        • M maydin

          Title is a bit confusing but if you find a better title feel free to change.

          I have a long operation in a C++ function, lets say 5 seconds, and I want to show a busy indicator until its finished.

          But Loader immediately loads the sourceComponent. I couldn't delay creation of sourceComponent.

          Loader {
          asynchronous: true
          sourceComponent: ColumnLayout {
                  property var myModel: Backend.longOperation() //5 seconds
          
                  Component.onCompleted: {
                        console.log("ready")
                  }
          
                  onMyModelChanged: {
                       console.log(JSON.stringify(myModel))
                  }
          }
          onStatusChanged: console.log(status)
          }
          

          Output as like this:

          2 // Loader.Loading
          ready
          1 // Loader.Ready
          // after 5 seconds
          [whats inside the object]
          

          It should wait my long operation then status should be ready so I can show a busy indicator.

          By the way, this is how I wait in C++ which might break things:

          QTime dieTime= QTime::currentTime().addSecs(5);
              while (QTime::currentTime() < dieTime)
                  QCoreApplication::processEvents(QEventLoop::AllEvents, 100);
          
          small_birdS Offline
          small_birdS Offline
          small_bird
          wrote on last edited by
          #4

          @maydin yes, change the visible property instead of opacity property. because when you lower the visible property to zero, it has no effect when you try to use mouse to manipulate it.

          1 Reply Last reply
          0
          • GrecKoG Offline
            GrecKoG Offline
            GrecKo
            Qt Champions 2018
            wrote on last edited by GrecKo
            #5

            Or read the doc and find that the first property listed actually do what you need:

            active property

            Or alternatively, use a BusyIndicator.

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved