Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-17868

QDeclarativePropertyMap::keys() cannot be called from qml

    XMLWordPrintable

Details

    • 0fdd97f613af6ae255e9cd1470ad8d4d67091dd7

    Description

      The following code does not work as expected. QML thinks that keys is a property that needs to be added instead of the Q_INVOKABLE function.

      test.cpp
      QDeclarativePropertyMap *test = new QDeclarativePropertyMap;
      test->insert("prop", QVariant(2));
      engine()->rootContext()->setContextProperty("test", test);
      
      test.qml
      console.log(test.keys())
      

      This code results in:
      TypeError: Result of expression 'test.keys' [undefined] is not a function.

      From what I was able to find, the function QDeclarativeOpenMetaObject::createProperty is called with keys, and then the property 'keys' is auto created. As a work around I overloaded the createProperty in QDeclarativePropertyMap and just checked if the created property is 'keys' and return a -1, but its not nice. I just dont know enough about the internals of the script and qml engines to propose a cleaner solution.

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            charles Charles Yin (closed Nokia identity) (Inactive)
            matspi Matt Spinder
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes