Then you need to call addpages() on that model instance, not create a new instance.
I.e. your code snippet looks like you are creating a new instance called "mod" on which you call addpages().
Cheers,
_
Printable View
Hello , i understand what you are saying .
My code goes like this .
1. Main.cpp : populate the views
Code:
if(!db.open()) { qDebug() <<"error in opening DB"; } else { qDebug() <<"connected to DB" ; } QVector<QString> page_id; QVector<QString> page_title; while (quer.next()) { page_id.push_back(i); page_title.push_back(p); } for (int i = 0; i < page_id.size(); ++i) { qDebug() << page_id.at(i).toLocal8Bit().constData() << endl; qDebug() << page_title.at(i).toLocal8Bit().constData() << endl; mod.addpages(list(page_title.at(i) , page_id.at(i))); } QQmlContext *ctxt = engine.rootContext(); ctxt->setContextProperty("myModel", &mod);
2. now this is how dbmanager.cpp calls the addpages()
i get the problem i.e. like you said creating new instance of listmodel ( first in main.cpp and other here in dbmanager.cpp )
so i need to pass the same instance in main.cpp to dbmanager right ?? Can i use pointers for that ?
Yes.
Or you do the initial load also in dbmanager.
Btw, your loading loop doesn't need local vectors, you can directly call addpages
Code:
while (quer.next()) { mod.addpages(p, i); }
You also might want to use QString::number(pageid), assuming pageid is a numerical value and you want that formatted into a string.
Cheers,
_
Thanks !! It's done :cool: