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. QML is crashing when the UI is blocked for some time in Windows
Forum Update on Monday, May 27th 2025

QML is crashing when the UI is blocked for some time in Windows

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
10 Posts 4 Posters 1.8k Views
  • 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.
  • N Offline
    N Offline
    Nmaster88
    wrote on last edited by Nmaster88
    #1

    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.

    J.HilkJ 1 Reply Last reply
    0
    • fcarneyF Offline
      fcarneyF Offline
      fcarney
      wrote on last edited by
      #2

      What version of Windows, version of Qt, and what C++ compiler?

      C++ is a perfectly valid school of magic.

      N 1 Reply Last reply
      0
      • Pradeep P NP Offline
        Pradeep P NP Offline
        Pradeep P N
        wrote on last edited by Pradeep P N
        #3

        Hi @fcarney
        I did test @Nmaster88 sample code in Windows 7, Desktop Qt 5.12.2 MinGW 32-bit
        Yes it crashes,

        0_1559969516833_10acfea0-ed45-4905-8045-b52aea9c9592-image.png

        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 the Layouts
        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 Nimbalkar.
        Upvote the answer(s) that helped you to solve the issue...
        Keep code clean.

        N 1 Reply Last reply
        0
        • fcarneyF fcarney

          What version of Windows, version of Qt, and what C++ compiler?

          N Offline
          N Offline
          Nmaster88
          wrote on last edited by
          #4

          @fcarney hello, I idited the code to provide that information.

          1 Reply Last reply
          0
          • Pradeep P NP Pradeep P N

            Hi @fcarney
            I did test @Nmaster88 sample code in Windows 7, Desktop Qt 5.12.2 MinGW 32-bit
            Yes it crashes,

            0_1559969516833_10acfea0-ed45-4905-8045-b52aea9c9592-image.png

            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 the Layouts
            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
            
            N Offline
            N Offline
            Nmaster88
            wrote on last edited by
            #5

            @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?

            Pradeep P NP 1 Reply Last reply
            0
            • N Nmaster88

              @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?

              Pradeep P NP Offline
              Pradeep P NP Offline
              Pradeep P N
              wrote on last edited by
              #6

              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 Nimbalkar.
              Upvote the answer(s) that helped you to solve the issue...
              Keep code clean.

              1 Reply Last reply
              1
              • N Offline
                N Offline
                Nmaster88
                wrote on last edited by
                #7

                @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?

                Pradeep P NP 1 Reply Last reply
                0
                • fcarneyF Offline
                  fcarneyF Offline
                  fcarney
                  wrote on last edited by fcarney
                  #8

                  @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

                  C++ is a perfectly valid school of magic.

                  1 Reply Last reply
                  0
                  • N Nmaster88

                    @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?

                    Pradeep P NP Offline
                    Pradeep P NP Offline
                    Pradeep P N
                    wrote on last edited by
                    #9

                    Hi @Nmaster88
                    Its only available from Qt 5.12

                    All the best.

                    Pradeep Nimbalkar.
                    Upvote the answer(s) that helped you to solve the issue...
                    Keep code clean.

                    1 Reply Last reply
                    0
                    • N Nmaster88

                      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.

                      J.HilkJ Offline
                      J.HilkJ Offline
                      J.Hilk
                      Moderators
                      wrote on last edited by J.Hilk
                      #10

                      @Nmaster88

                      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?


                      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                      Q: What's that?
                      A: It's blue light.
                      Q: What does it do?
                      A: It turns blue.

                      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