PDA

View Full Version : How to access c++ vector in QML



GAURAV PANT
15th March 2014, 03:18
Hi,
I am developing QT widget application and for one UI part i have used QML also.
I am facing problems in using vector type in QML file.

QT widget code:

vector<controller> *vectorObj (Controller is class)

controller *ob1=new controller();
ob1->setName("GP");
ob1->setId("2");

controller *ob2=new controller();
ob2->setName("PM");
ob2->setId("5");

vectorObj->push_back(ob1);
vectorObj->push_back(ob2);

Now vector is holding two objects of class Controller.

QML File :

Now in QML file i have two rows and each row has two columns.
In row1 i want to display ob1.getName() and ob1.getID()
and in row 2 i want to display ob2.getName and ob2.getID()

I tried using QProperty but unable to get values.
Might be i have used QProperty in some wrong way or if there is some other way to achieve same then please share.


Thanks

anda_skoa
15th March 2014, 15:51
Have you considered a table model with the vector as its data?

Cheers,
_