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. How to fetch listtype data from qml to cpp?
Forum Updated to NodeBB v4.3 + New Features

How to fetch listtype data from qml to cpp?

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
qmlqqmlcomponentqqmlengineqmetaobjectinvokemethod
1 Posts 1 Posters 239 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.
  • J Offline
    J Offline
    Joshika_Namani
    wrote on 15 Dec 2021, 09:16 last edited by
    #1

    In below program I have used QmlComponent and QMetaObject::invokeMethod its getting for single value but for list it showing error:"ASSERT failure in QList<T>::operator[]: "index out of range"
    Here My code:

    main.cpp
    QQmlEngine engine;
    QQmlComponent component(&engine,QUrl(QStringLiteral("qrc:/MyItem.qml")));
    QObject *object = component.create();
    QVariant returnedValue;
    QMetaObject::invokeMethod(object, "names",
    Q_RETURN_ARG(QVariant, returnedValue));
    qDebug() << "QML function returned:" << returnedValue.toString();
    delete object;

    main.qml

    Item {
    property string name: "apple"
    property string two: "banana"
    property string three: "mango"
    property string one: "lemon"
    property string four: "watermelon"
    property string five: "pineapple"
    property var list: [name,two,three,one,five,four]
    function names()
    {
    console.log("names function");
    var arr= [name,two,three,one,five,four];
    return arr;
    }
    }

    1 Reply Last reply
    0

    1/1

    15 Dec 2021, 09:16

    • Login

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