复杂数据结构的 Qt 模型/视图编程

发布于 2024-07-29 23:51:01 字数 261 浏览 5 评论 0原文

我不是专业的应用程序开发人员,因此可能不太熟悉模型/视图设计模式。 尽管如此,我试图在业余爱好应用程序中使用它,但惨遭失败。 我遇到的主要问题是我尝试显示和修改的数据不容易用 QAbstractItemModel 扩展来表示。

我试图封装的数据本质上是一个可增长/可收缩、可变的整数列表。 我应该放弃这样的数据的模型/视图模式吗? 当数据的“维度”固定时,这似乎更合适。 如果没有,是否有一个我可以看一下的实现示例,或者我应该拿起一本好书?

问候。

I am not a professional application developer so am probably not as familiar with the model/view design pattern as I should be. Nonetheless, I am trying to use it in a hobby app and failing miserably. The primary problem I am having is that the data I am trying to display and modify is not easily represented with an extension of QAbstractItemModel.

The data I am trying to encapsulate is essentially a growable/shrinkable, mutable list of integers. Should I abandon the model/view pattern for data like this? It seems more appropriate when the "dimensions" of the data are fixed. If not, is there an example of an implementation that I could take a gander at, or a good book that I should pick up?

Regards.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

北城孤痞 2024-08-05 23:51:01

我会看看 QAbstractListModel。 这听起来像是一个比基本的 QAbstractItemModel 更相关的模型。

在示例中该模型还有一个相当不同的视图: 谜题

如果您需要更高层次地了解模型/视图,请查看

I would look at QAbstractListModel. It sounds like a more relevant model than the basic QAbstractItemModel.

There is also a rather different view of that model in the example: Puzzle

If you need a higher level look at Model/View, check out this.

舞袖。长 2024-08-05 23:51:01

QAbstractItemModel 只是一种不可否认的实现模型/视图设计模式的非常有限的方法。 如果你发现你的情况不太适合它,不要费力去强迫它。

对您来说,更好的方法可能是只使用自己的 View 类来提取自己的 Model 类,并放弃 QAbstractItemModel 。 这种设计模式不仅仅是 QT 中实现的奇怪风格,而且这种风格只适用于非常特定的应用程序。

我建议您阅读更多内容并设计您自己的模型视图设置。 如果你自己动手,你的类设计很可能会更清晰、更好理解。

QAbstractItemModel is just one, admittedly very limited way of implementing the Model/View design pattern. If you see that your situation doesn't fit it neatly don't bother working too hard to force it.

A better approach for you would probably be to just pull your own Model class with your own View classes and abandon QAbstractItemModel. There is more to this design pattern than the weird flavor implemented in QT and that flavour only works well for very particular applications.

I suggest you read about it some more and design your own Model-View setup. Your class design is very likely to be cleaner and better understood if you pull your own.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文