Qt 5.3 QML Application crashes with associative array



  • Since 5.3 an QML application crashes if I'm using an associative array with more than 10 elements. With 10 or less elements, the application works. With Qt 5.2 this wasn't an issue

    @import QtQuick 2.2

    Rectangle {
    width: 360
    height: 360

    property variant colors: {
                "0": "#80ffd618",
                "2": "#80c21717",
                "5": "#8076210e",
                "8": "#80faea3b",
                "6": "#8076210e",
                "12": "#809c831f",
                "13": "#80baae2d",
                "16": "#805e2722",
                "18": "#805e2532",
                "39": "#80cd5834",
                "40": "#80c20f2e"
    }
    
    Text {
        anchors.centerIn: parent
        text: "Hello World"
        color: colors["40"]
    }
    

    }@


  • Moderators

    Looks like a bug, please report it on "Jira":https://qt-project.org/wiki/ReportingBugsInQt.



  • are you sure that worked before? I could never get it to work to assign objects to properties directly. I thought that is a feature of QML and the {} are parsed as a function like you do with slots (onClicked: {} is a slot and not an JS object as far as I know).

    So with Qt 5.2 and 5.2.1 it is a QMl syntax error to do something like
    @
    property var foo: {}
    @
    or do you have to use variant in that case? I thought you should always use "var" instead of variant in newer version of Qt?

    anyway my solution is to use a helper function that always works:
    @
    property var foo: getFoo()
    function getFoo() {
    return { ... }
    }
    @



  • Braces in property initialisations are treated as binding expression delimiters. You need to wrap them in parentheses or explicitly call the Object constructor function to achieve the behaviour you want.

    property variant foo: ({ "something": 1 })
    property variant bar: { var temp = new Object(); temp.something = 1; return temp; }

    Cheers,
    Chris.



  • Thanks for reply. I'm sure it is working in 5.2. I migrated an application from 5.2 to 5.3 and the same application is still working with Qt 5.2

    Even the above changes from variant to var, the definition of a function or wrapping with parentheses does not change anything. The application crashes too.

    The associative array works with 10 or less elements. Only with more than 10 elements the application crashes.



  • maybe the crash is related to something else then, did you take a look at the stacktrace when the app crashes and where exactly it does.



  • No, it's related to the associative array.
    Qt provided already a fix https://codereview.qt-project.org/#change,82113


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.