QML中数组的最大大小是多少?

时间:2019-05-20 08:12:57

标签: qt qml

我在用qml构建对象数组时遇到问题,我认为问题与数组中可能的大小限制有关。

我将用一部分代码来说明我想做什么:

main.qml

import QtQuick 2.0
import QtQuick.Controls 1.4
import QtQuick.Controls 2.0
import QtQuick.Layouts 1.3

ApplicationWindow {
    id: window
    title: "Stack"
    visible: true
    width: 1400
    Page {
        id: page
        anchors.fill: parent
        property int responsiveWidth: 1000
        property int maximumWidth: 900
        ScrollView {
            id:configScroll
            anchors.fill: parent
            GridLayout {
                columns: 2
                width: page.width > page.responsiveWidth ? page.maximumWidth : page.width
                anchors.top: parent.top
                anchors.left: parent.left
                anchors.leftMargin: page.width > page.responsiveWidth ? (page.width - childrenRect.width)/2 : 10
                anchors.rightMargin: page.width > page.responsiveWidth ? 0 : 10
                    Button {
                        property bool test: true
                        text: "array func"
                        onClicked: {
                            var panelModes=[], rows=[],groupsModes=[], panelLabel="panel", sounderLabel="sounder",soundersModeLabel="sounder mode",sounderGroupLabel="sounder group"
                            for(var gSndrModeAdd=0; gSndrModeAdd<1000;gSndrModeAdd++) {
                                panelModes = []
                                for(var pSndrModeAdd=0; pSndrModeAdd<32; pSndrModeAdd++) {
                                    rows = []
                                    rows.push(["C1",1])
                                    rows.push(["C2",1])
                                    for(var sSndrModeAdd=0; sSndrModeAdd<32; sSndrModeAdd++) {
                                        rows.push(["L1S"+(sSndrModeAdd+1),1])
                                        rows.push(["L2S"+(sSndrModeAdd+1),1])
                                        rows.push(["L3S"+(sSndrModeAdd+1),1])
                                        rows.push(["L4S"+(sSndrModeAdd+1),1])
                                    }
                                    panelModes.push({"label":panelLabel, "value": 1, "headers":[sounderLabel,soundersModeLabel],"rows":rows})
                                }
                                groupsModes.push({"label":sounderGroupLabel,"value":1,"nested":panelModes})
                            }
                            console.log("the array is: ")
                            console.log(groupsModes)
                        }
                    }
            }
        }
    }
}

这崩溃了。

如果这不是数组问题,那么这是否是内存大小问题?像这样的东西?

但是有必要构建我想要的结构。有办法解决吗?之后,我需要将其发送到c ++后端的函数中。

我在控制台上遇到的错误:

09:45:07: The program has unexpectedly finished.

09:45:07: The process was ended forcefully.

09:45:07: C:/Dev/QT/build-array-crash-limit-Desktop_Qt_5_11_1_MinGW_32bit-Debug/debug/array-crash-limit.exe crashed.

如果我将第一个周期设为300,我就设法用Memory usage抓住了QML Profilerenter image description here enter image description here

2 个答案:

答案 0 :(得分:1)

您在这里有错误

...
for(var pSndrModeAdd=0; 32; pSndrModeAdd++) {
...

,循环将永远运行。更改为

...
for(var pSndrModeAdd=0; pSndrModeAdd<32; pSndrModeAdd++) {
...

无论如何,QML中的数组只是JavaScript数组,因此(实际上)没有最大大小。

答案 1 :(得分:0)

原来,该应用程序的崩溃仅在Windows平台上发生。 在MACOS和LINUX中,它仅在函数处理时阻塞。

也许这毕竟是内存问题,发生在使用QT版本且使用MinGW 32位的Windows上。

解决此问题的解决方案? MinGW 64位的用法。

相关问题