Delaying loading object of a loader
-
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);
-
How about setting the sourecomponent property value when the task is finished ?
-
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 ...
-
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);
@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.
-
Or read the doc and find that the first property listed actually do what you need:
Or alternatively, use a
BusyIndicator
.