QML is crashing when the UI is blocked for some time in Windows
-
I'm developping an application that runs a function that takes some time to process, the application gets blocked for some time.
For the user to known that the app is processing information i show a spinner.
This processing takes some time, lets say a minute, the whole app is blocked but it works well on MACOS and LINUX systems but on WINDOWS the app crashes!I'm going to illustrate what its happening with the simple code:
import QtQuick 2.0 import QtQuick.Controls 2.4 import QtQuick.Layouts 1.3 ApplicationWindow { id: window title: "Stack" visible: true width: 600 height: 500 Page { id: page anchors { fill: parent margins: 10 } ColumnLayout { anchors.fill: parent spacing: 10 RowLayout { id: testRowLayout function bigfunction() { var teste = 0 var arrayTeste = [] for(var i=0; i< 100000; i++) teste +=i arrayTeste.push(i) for(var j=0; j<100000;j++) { teste +=j arrayTeste.push(j) for(var z=0; z<10000; z++) { teste +=z arrayTeste.push(z) } } console.log(teste) spinner.running = false } BusyIndicator { id: spinner anchors.centerIn: parent running: false } Button { Layout.alignment: Qt.AlignHCenter text: qsTr("Run function") onClicked: { spinner.running = true testRowLayout.bigfunction() } } } Item { Layout.fillHeight: true } } } }
I known some would say that the way to go is to use WorkerScripts, C++ threads and things like that. I know that can be done and that way the UI wont be blocked.
But the App i'm developing its not a simple task to just do that as i'm using function and variables from components and i don't want to duplicate code in the application.
The question is how to prevent WINDOWS from crashing?Using qt 5.11.1, minGw 32-bit compiler and windows 10.
-
Hi @fcarney
I did test @Nmaster88 sample code in Windows 7, Desktop Qt 5.12.2 MinGW 32-bit
Yes it crashes,Works fine on Desktop Qt 5.12.2 MinGW 64-bit
@Nmaster88 ,
So as you mentioned the code works in MAC & Linux, is it the same code you have provided the sample or the other code (Master Copy) ?
And in the above code the UI itself completely freezed, so there is no point you can see the BusyIndicator till the function is completed.Note: Avoid using
anchors
inside theLayouts
small updates in your code related to above note.import QtQuick 2.0 import QtQuick.Controls 2.4 import QtQuick.Layouts 1.3 ApplicationWindow { id: root visible: true width: 600 height: 500 Page { id: page anchors { fill: parent margins: 10 } ColumnLayout { anchors.fill: parent spacing: 10 RowLayout { id: testRowLayout Layout.fillWidth: true Layout.fillHeight: true Layout.alignment: Qt.AlignHCenter BusyIndicator { id: spinner running: runBtn.pressed } Button { id: runBtn text: qsTr("Run function") onClicked: { root.bigfunction(); } } } Item { Layout.fillHeight: true Layout.fillWidth: true Rectangle { anchors.fill: parent color: 'transparent' border { color: 'black' width: 5; } } } } } function bigfunction() { console.log("Started Function") var teste = 0 var arrayTeste = [] for(var i=0; i< 10000; i++) { teste +=i } arrayTeste.push(i) for(var j=0; j<10000;j++) { teste +=j arrayTeste.push(j) for(var z=0; z<10000; z++) { teste +=z arrayTeste.push(z) } } console.log("Finished :: ", teste) spinner.running = false } } Output : qml: Started Function qml: Finished :: 500049990000
-
@Pradeep-P-N hello, I did not test this code on Mac and Linux but the other code. When I can I will test it. But the conditions are the same, So, compiler and qt version.
The problem maybe on the compiler then?
-
Hi @Nmaster88 ,
May be, we have to debug it with MinGW 32-bit.
Please try with MinGW 64-bit, i also tested it with GCC 64bit it works fine.All the best.
-
@Pradeep-P-N strange i see that you tested in qt5.12.2 and you installed minGW 64-bit.
but i'm with qt5.11.1 and when i go to maintenance tool of QT in add/remove components there is not minGW 64-bit only the 32-bit.
Is it possible to install the 64-bit compiler?
-
@Nmaster88 said in QML is crashing when the UI is blocked for some time in Windows:
not minGW 64-bit only the 32-bit
I think it was 5.12.2/3 that started shipping both a 32 bit compiler and 64 bit. So in order to get the 64 bit you would have to go to a version of 5.12.
Edit For Windows mingw
-
Hi @Nmaster88
Its only available from Qt 5.12All the best.
-
you're making a 10000 * 10000 * 10000 array, that's 10 to the power of 12 entries, each 4 bytes, as it's a double by default.
I think, you're simply running out of memory, or do you have 4terabyte of memory available to you?