Qt 模型视图更新视图? [英] Qt Model-View update view?

查看:76
本文介绍了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?

示例:

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

在某个时间点,dynamic_list 通过套接字连接填充了新条目(与视图无关).如何用新数据填充视图?

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?

推荐答案

模型必须发出信号以在其数据更改时通知视图.根据数据更改的准确程度选择适当的信号:

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

  • dataChanged 信号强制视图更新特定单元格,但不创建或删除单元格.
  • layoutAboutToBeChangedlayoutChanged 信号强制视图更新所有内容.
  • 有关添加或删除行和列的信号会强制视图相应地更新.
  • 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.

这篇关于Qt 模型视图更新视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆