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. [solved] QQmlListProperty from QList
Forum Updated to NodeBB v4.3 + New Features

[solved] QQmlListProperty from QList

Scheduled Pinned Locked Moved QML and Qt Quick
4 Posts 3 Posters 3.0k 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.
  • V Offline
    V Offline
    Viilai
    wrote on last edited by
    #1

    All the examples I've found online say to do what I've done in the following example, however I get an error.

    @QQmlListProperty<QString> ReadXML::listElements()
    {
    QList<QString> eleList;
    eleList.append("one");
    eleList.append("two");
    eleList.append("three");

    return QQmlListProperty<QString>(this, eleList);
    

    }@

    @readxml.cpp:14: error: C2665: 'QQmlListProperty<QString>::QQmlListProperty' : none of the 5 overloads could convert all the argument types
    d:\qt\qt5.3.2\5.3\msvc2013_opengl\include\qtqml\qqmllist.h(67): could be 'QQmlListProperty<QString>::QQmlListProperty(QObject *,QList<T *> &)'
    with
    [
    T=QString
    ]
    while trying to match the argument list '(ReadXML *const , QList<QString>)'@

    Due to the lack of information given by the compiler I don't know how to troubleshoot it. It sounds as if it is telling me to do this:

    @return QQmlListProperty<QString>(this, eleList<QString>);@

    But that just results in it complaining:
    @readxml.cpp:14: error: C2275: 'QString' : illegal use of this type as an expression@

    I would appreciate any help.

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andreyc
      wrote on last edited by
      #2

      From the declaration QQmlListProperty(QObject ,QList<T > &) requires a list of the pointers to some type.
      You are providing a list of types.
      Try this
      @
      QQmlListProperty<QString> ReadXML::listElements()
      {
      QList<QString
      > eleList;
      QStringList sourceList;
      source << "one" << "two" << "three";
      for(QString source : sourceList) {
      QString
      string = new QString(source);
      eleList.append(string);
      }
      return QQmlListProperty<QString>(this, eleList);
      }
      @

      1 Reply Last reply
      0
      • GianlucaG Offline
        GianlucaG Offline
        Gianluca
        wrote on last edited by
        #3

        But are you trying to pass a list of QString ?!?! If yes, then QStringList is already QML friendly. So, you don't need to create a QQmlListProperty for containing a list of QString, just return a QStringList from the slot:

        @
        QStringList ReadXML::listElements() {
        QStringList eleList;
        eleList.append("one");
        eleList.append("two");
        eleList.append("three");
        return eleList;
        }
        @

        1 Reply Last reply
        1
        • V Offline
          V Offline
          Viilai
          wrote on last edited by
          #4

          Thank you both.

          Gianluca - good to know, and andreyc's is good reference for future requirements.

          Cheers

          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