0

I'm designing a Qt UI and have two different views ( QGraphicsObject class) for the same model (a car).

When the car's model is to be updated (in one of two widgets), I want both of the views to be updated (and of course the same goes for the model).

The intuitive way to do this is to update the model, and let the views catch a 'signal' or something similar when this happens to update themselves.

I want to know if this is a recommended behavior (in MVC) as it forces the model to have some bidirectional connection with its views (while in MVC the model shouldn't have a list of its views).

Also, what's a good way to implement this in Qt ? (use Qt signals ? raise a flag when the model have been changed ?)

4

1 回答 1

0

你的模型会是什么样子?在 Qt 中,有一个用于类似列表、类似表格和类似树的模型的标准 API,即模型视图编程QGraphicsScene但是,您显然正在使用它并不能很好地发挥作用。你还没有说你想用什么来沟通,或者你建模的数据是如何结构化的,所以很难建议你在这里应该做什么。

也就是说,通常的 MVC 模式(对QAbstractItemModelQt 中使用的 API 进行数学运算)是让模型通知任何附加视图有关基础数据的任何更改;在 Qt 中,这是通过视图连接的信号来完成的。当视图想要修改数据时,它们会调用模型上的方法。当模型接受修改时,它会发出标准信号,以便之后更新所有视图。

于 2013-04-24T14:38:58.297 回答