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. Automatic conversion of QList<QString> is not a JS array of strings?
Forum Updated to NodeBB v4.3 + New Features

Automatic conversion of QList<QString> is not a JS array of strings?

Scheduled Pinned Locked Moved Solved QML and Qt Quick
3 Posts 2 Posters 788 Views
  • 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.
  • D Offline
    D Offline
    Diracsbracket
    wrote on 26 Nov 2020, 21:58 last edited by Diracsbracket
    #1

    Hi.
    I wish to set the model of a ListView to a QList<QString> passed from C++ via a Q_INVOKABLE function call.

    According to the Qt docs, the conversion from QList<QString> to a JavaScript array is automatic.

    Yet, the view does not show the data. If I set the model directly in QML to a JS string array with exactly the same strings however it works.
    Converting it explictly to a JS array with Array.from() also works.

        property var names: []
    
        Component.onCompleted: {
            names = um.getNames()
    
            //console.debug(names) //<-- shows [Name1,Name2]
    
            //view.model = ["Name1", "Name2"]      //<-- WORKS
            //view.model = [names[0], names[1]]   //<-- WORKS
            //view.model = Array.from(names)         //<-- WORKS
    
            view.model = names // <-- DOES NOT WORK ??
       }
    

    What am I missing here? Is the implicit conversion done by the QML engine of a QList<QString> not a normal JS array of strings?

    1 Reply Last reply
    0
    • G Offline
      G Offline
      GrecKo
      Qt Champions 2018
      wrote on 27 Nov 2020, 01:55 last edited by
      #2

      Have you tried with QStringList?

      D 1 Reply Last reply 8 Dec 2020, 03:42
      0
      • G GrecKo
        27 Nov 2020, 01:55

        Have you tried with QStringList?

        D Offline
        D Offline
        Diracsbracket
        wrote on 8 Dec 2020, 03:42 last edited by
        #3

        @GrecKo
        QStringList works without conversion to Array. So only the QList<QString> conversion is not transparent.

        Thanks.

        1 Reply Last reply
        1

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved