PDA

View Full Version : QAbstractListModel - QListView not actualized continously..



xrep
11th February 2012, 17:15
Hello,

I wrote my own read-only model

webPageModel.h

class webPageModel : public QAbstractListModel {

Q_OBJECT

public:

webPageModel(QList<wPage *> * st, QObject *parent = 0) : QAbstractListModel(parent) {
pagesList = st;
show();

}

int rowCount(const QModelIndex &parent = QModelIndex()) const;
QVariant data(const QModelIndex &index, int role) const;



private:
QList<wPage *> * pagesList;
};


webPageModel.cpp

int webPageModel::rowCount(const QModelIndex &parent) const {
return pagesList->count();
}

QVariant webPageModel::data(const QModelIndex &index, int role) const {

if (!index.isValid())
return QVariant();

if (index.row() >= pagesList->size())
return QVariant();

if (role == Qt::DisplayRole)
return pagesList->at(index.row())->getUrl().toString();
else
return QVariant();
}

Timeline
I create list
I create model
view is connected to model
then I am adding elements to list

the problem is, that in time when I am creating model, pagesList is empty. Elements in pagesList are added continuously after I create model.
So View stays empty, until process that fills pagesList stops, than view shows elements all at once (absolutely don't know why, is view doing some automatic? because pointer pagesList does not change with time).

I would be happy if elements can be added to qlistview concurently with adding to pagesList, and dont know how.

It will be working if I add list directly into model? (now there is just pointer to the list)
I suppose there is needed some singals/slot/emit magic?

Can somebody explain or give some good example? I read http://developer.qt.nokia.com/doc/qt-4.8/model-view-programming.html but without success..

Thanks

dieter
11th February 2012, 18:11
I only have a good example for you...
http://developer.qt.nokia.com/doc/qt-4.8/model-view-programming.html

xrep
23rd February 2012, 11:52
added reset() into model::insert() method in model