print c++ data in qml list view
Solved
Mobile and Embedded
-
Hi,
What kind of data are you talking about ?
-
class resource: public QObject { Q_OBJECT public: resource(QString); ~resource(); Q_INVOKABLE void addLoss(float, float); Q_INVOKABLE float getLoss(); Q_INVOKABLE QString getName(); private: QString name; QList<float> *Loss; };
my data class is above. and i made resource list as bleow
in main.cpp
QList<resource*> *resourceArr; qDebug()<< "declare resourceArr"; resourceArr = new QList<resource*>; resource *a = new resource("name"); resourceArr->push_back(a); QQmlApplicationEngine engine; QQmlContext *context = new QQmlContext(engine.rootContext()); // c++ class to qml object context->setContextProperty("resourceVec", &resourceArr);
last line gives me an error like "calling a private constructor of class 'QVariant'"
and also "atemp to use a deleted function"what i want is print resourceArray[idx].getName() / resourceArray[idx].getLoss() in my listView.
problem looks simple but i have a hard time with it..... i'm noob in qt.
-
You are passing a pointer to the pointer of your QList object. That's wrong.