PDA

View Full Version : QListView does not display its model



mtrpoland
22nd February 2008, 19:24
I have met an odd obstacle.
QListView does not display my subclass of QAbstractListModel even though everything is done as usually (I suppose).
//Model subclass
http://www.mjakobczyk.pl/pub/hostInfoModel.hpp
http://www.mjakobczyk.pl/pub/hostInfoModel.cpp
//Data
http://www.mjakobczyk.pl/pub/hostInfo.hpp
http://www.mjakobczyk.pl/pub/hostInfo.cpp

Usage is as follows:
In constructor:
hostInfoModel = new HostInfoModel(hostList,this);
listView = new QListView;
listView->setModel(hostInfoModel);

User clicks "refresh list" button that is followed by 10 secs of udp hunting.
Each diffrent packet is parsed and MTR::HostInfo are created and placed into the QList<MTR::HostInfo>.
It does work.
Then hostInfoModel->setHostInfoList(hostInfoList);
It does work as during tests rowCount showed number of MTR::HostInfo objects inside.
and now I suppose listView should display its model data but the problem is that with qDebug I have found out that MTR::HostInfoModel::data() is not evoked even once.

jpn
22nd February 2008, 19:31
HostInfoModel::setHostInfoList() does not inform the model-view framework that the internal data structure changes. You should call for example QAbstractItemModel::reset().

PS. Attach files on this forum next time instead of linking to external sites, please.