Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Qt Model-View update view?

Tags:

view

qt

I have a model which is updated dynamically not related to the view. Which method should be called on the view to show the current models data?

Example:

StationListModel *model = new StationListModel(dynamic_list);
QListView *view = new QListView;
view->setModel(model);  //view set with empty model 
view->show();

In some point in time the dynamic_list is populated with new entries via a socket connection (nothing to do with View). How to populate the view with new data?

like image 770
TheMeaningfulEngineer Avatar asked Oct 31 '13 12:10

TheMeaningfulEngineer


1 Answers

Model must emit signals to notify views when its data changed. Choose appropriate signals depending on how exactly data is changed:

  • dataChanged signal forces view to update specific cells, but not to create or remove cells.
  • layoutAboutToBeChanged and layoutChanged signals forces view to update everything.
  • signals about adding or removing rows and columns forces view to update accordingly.
like image 174
Pavel Strakhov Avatar answered Oct 13 '22 01:10

Pavel Strakhov