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. Qt 5.3 QML Application crashes with associative array
Forum Updated to NodeBB v4.3 + New Features

Qt 5.3 QML Application crashes with associative array

Scheduled Pinned Locked Moved QML and Qt Quick
7 Posts 4 Posters 3.5k Views 1 Watching
  • 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.
  • M Offline
    M Offline
    Maxwell77
    wrote on last edited by
    #1

    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"]
    }
    

    }@

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

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

      (Z(:^

      1 Reply Last reply
      0
      • X Offline
        X Offline
        Xander84
        wrote on last edited by
        #3

        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 { ... }
        }
        @

        1 Reply Last reply
        0
        • C Offline
          C Offline
          chrisadams
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          0
          • M Offline
            M Offline
            Maxwell77
            wrote on last edited by
            #5

            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.

            1 Reply Last reply
            0
            • X Offline
              X Offline
              Xander84
              wrote on last edited by
              #6

              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.

              1 Reply Last reply
              0
              • M Offline
                M Offline
                Maxwell77
                wrote on last edited by
                #7

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

                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