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. QML : Error: Unknown method return type: QList<QStringList>
Forum Updated to NodeBB v4.3 + New Features

QML : Error: Unknown method return type: QList<QStringList>

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
4 Posts 3 Posters 3.6k Views 2 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.
  • I Offline
    I Offline
    Iheb
    wrote on last edited by Iheb
    #1

    Hello, I have a function in Qt that returns QList<QStringList> object and I'm using it in a QML file. The compilation is fine. However, when executing it the QML throws this error : Unknown method return type: QList<QStringList>. Please help.

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      You need to register this type using Q_DECLARE_METATYPE. Also you'll probably need to use qRegisterType(), but I'm not sure. Look it up in the documentation.

      (Z(:^

      1 Reply Last reply
      2
      • I Offline
        I Offline
        Iheb
        wrote on last edited by
        #3

        Thank you for the reply. I tried different things but no success. Can you please give me an example?

        ODБOïO 1 Reply Last reply
        0
        • I Iheb

          Thank you for the reply. I tried different things but no success. Can you please give me an example?

          ODБOïO Offline
          ODБOïO Offline
          ODБOï
          wrote on last edited by ODБOï
          #4

          @Iheb hi
          you can return a QVariant instead of QList<QStringList>

             Q_INVOKABLE QVariant getlistOfLists(){
                  
                  QList<QStringList> listOfLists;
                  QStringList l1;
                  l1<<"str1";
                  QStringList l2;
                  l2<<"str2";
                  QStringList l3;
                  l3<<"str3";
                  QStringList l4;
                  l4<<"str4";
          
                  listOfLists<<l1<<l2<<l3<<l4;
                  return  QVariant::fromValue(listOfLists);
              }
          
            Component.onCompleted: {
                  var listsList = testObj.getlistOfLists()
                  for(var i in listsList){
                      console.log(listsList[i][0])
                  }
              }
          
          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