I am trying to implement busy indicator in my application. But the current implementation is not working correctly.
---Main.qml----
import QtQuick 2.4
import QtQuick.Controls 1.3
import QtQuick.Window 2.2
import QtQuick.Dialogs 1.2
ApplicationWindow {
title: qsTr("Hello World")
width: 640
height: 480
visible: true
BusyIndicator {
id: indicator
running: false
}
MainForm {
anchors.fill: parent
button1.onClicked: {
indicator.running = true
console.info(indicator.running)
obj.runWorkerFunction()
indicator.running=false
console.info(indicator.running)
}
}
}
---Testclass.cpp----
#include "testclass.h"
#include <QDebug>
#include <QThread>
TestClass::TestClass(QObject *parent) : QObject(parent)
{
}
TestClass::~TestClass(){
}
void TestClass::workerFunction() {
for(int i = 0; i < 1000; i++){
qDebug() << i;
}
qDebug() << "Done";
}
void TestClass:: runWorkerFunction(){
// QThread* thread = QThread::create([this]() {
// workerFunction();
// emit workerFinished();
// });
// thread->start();
workerFunction();
}
---Main.cpp
#include <QApplication>
#include <QQmlApplicationEngine>
#include <QQmlContext>
#include "testclass.h"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
TestClass obj;
QQmlApplicationEngine engine;
QQmlContext *context = engine.rootContext();
context->setContextProperty("obj", &obj);
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
return app.exec();
}
I have tried using Thread which is currently commented out, but busy indicator does not work. The goal is to show the indicator only during the worker thread performs heavy calculation. Additionally with Connections binding I could not make it work. Can anyone help me out with this problem or provide some alternate solution.
Thank you