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

Make QML ListModel compilable by qmlsc

    XMLWordPrintable

Details

    Description

      Its public methods use QQmlV4Function and QJSValue as parameters or return values, which makes them uncompilable. Example at https://github.com/qt/qtdeclarative/blob/v6.5.2/src/qmlmodels/qqmllistmodel_p.h#L68-L72 :

      Q_INVOKABLE void remove(QQmlV4Function *args);
      Q_INVOKABLE void append(QQmlV4Function *args);
      Q_INVOKABLE void insert(QQmlV4Function *args);
      Q_INVOKABLE QJSValue get(int index) const;
      Q_INVOKABLE void set(int index, const QJSValue &value);
      

       

      Code
      Adapted from https://doc.qt.io/qt-6/qml-qtquick-controls-combobox.html#accepted-signal

      ComboBox {
          model: ListModel {
              id: model
              ListElement { text: "Apple" }
              ListElement { text: "Banana" }
              ListElement { text: "Coconut" }
          }
          Component.onCompleted: console.log("First fruit is", model.get(0).text)
      }
      

       

      qmlsc output

      Warning: Main.qml:16:69: Could not compile binding for onCompleted: Cannot generate efficient code for lookup in QJSValue [compiler]
              Component.onCompleted: console.log("First fruit is", model.get(0).text)
                                                                                ^^^^
      

      Attachments

        Issue Links

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

          Activity

            People

              qt.team.quick.subscriptions Qt Quick and Widgets Team
              skoh-qt Sze Howe Koh
              Votes:
              1 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:

                Gerrit Reviews

                  There are no open Gerrit changes