[Qt-interest] Howto dynamically update QListView's Items and Howto Insert/Read Datas ?

Ulf-Alexander v. Ceumern-Lindenstjerna ceumern at vrmagic.com
Wed Mar 17 15:43:45 CET 2010


> I) How to dynamically update QListView ?
>    I shouldn't need to use setModel to reset it everytime , right ?

No, you do not update the view, but rather update the model! The model
takes care of notifying the view to update itself.
You can access the model by calling ui->listView->model() and
dynamic_cast it to a QStringListModel*.
Or (preferred) you just remember the model you put in to the view:

m_model = new QStringListModel(listStr); // assign to member
ui->listView->setModel(m_model);

I suggest you do some reading about the whole model/view architecture:
http://doc.trolltech.com/4.6/model-view-introduction.html


> II) How to read items / insert items ?
>     For this one , i have totally no idea ..

See http://doc.trolltech.com/4.6/qstringlistmodel.html :

virtual bool 	insertRows  ( int row, int count, const QModelIndex &
parent  = QModelIndex() )
virtual bool 	removeRows ( int row, int count, const QModelIndex &
parent = QModelIndex() )
virtual int 	rowCount ( const QModelIndex & parent = QModelIndex() )
const
virtual bool 	setData ( const QModelIndex & index, const QVariant &
value, int role = Qt::EditRole )

regards, ulf




More information about the Qt-interest-old mailing list