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

qmlsc: list<string> vs QStringList

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P2: Important
    • 6.6.0
    • 6.5.0 RC
    • QML: Compiler
    • None
    • 653a6ff82a6321a7f41d84ab3754ab5d10ed1d5a

    Description

      There seems to be no way (besides using var) to pass a list<string> to a QStringList, currently:

      Window {
          property list<string> someList: ["foo", "bar"]
      
          Component.onCompleted: {
              Foo.names = someList;
          }
      }
      

      and

      class Foo : public QObject {
          Q_OBJECT
          QML_ELEMENT
          QML_SINGLETON
      
          Q_PROPERTY(QStringList names READ names WRITE setNames NOTIFY namesChanged FINAL)
      
      public:
          explicit Foo(QObject* parent = nullptr) : QObject(parent) {}
      
          QStringList names() const { return m_names; }
          void setNames(const QStringList& list) { m_names = list; emit namesChanged(); }
      
      signals:
          void namesChanged();
      
      private:
          QStringList m_names;
      };
      

      renders into

      Warning: Main.qml:14:21: Could not compile binding for onCompleted: cannot convert from QList<QString> of (component in /var/home/prcs1076/tmp/build-andyflick-Desktop_Qt_6_5_0_GCC_64bit-Debug/Main.qml)::someList with type QString to QStringList of Foo::names with type QStringList [compiler]
              Foo.names = someList;
                          ^^^^^^^^
      

      . Which is technically correct, of course. Using "var" says

      Warning: Main.qml:11:28: Could not compile binding for someList: Cannot generate efficient code for storing an array in a non-sequence type [compiler]
          property var someList: ["foo", "bar"]
                                 ^
      

      .

      So changing the API is the only way to get rid of warnings.

      Attachments

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

        Activity

          People

            qtqmlteam Qt Qml Team User
            cajus Cajus Pollmeier
            Votes:
            1 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes