gpt4 book ai didi

c++ - Qt:Qt 新手问题

转载 作者:行者123 更新时间:2023-11-30 04:40:11 25 4
gpt4 key购买 nike

我已经编写了一个类,我正在尝试将它连接到 Qt。我有一些“最佳实践”问题,希望大家能帮助我。

  • 在创建包含数据的主窗口时,我将头文件继承到上面指定的自定义类中,因此我可以使用在 Qt Creator 中创建的元素。这是做事的正确方法吗?我从official book的第二章借用了这个想法。我是否应该创建一个将它们绑定(bind)在一起的新类?

  • 我应该在类内部严格封装数据,还是使其对同类类友好?这对可访问性有帮助吗?

  • 除了官方书籍关于MVC的章节,还有在线教程here ,Qt 中的 MVC 新手还有哪些其他资源?

提前致谢

最佳答案

When creating a mainWindow to contain data, I inherit the header file into my custom class specified above, so I can make use of the elements created within Qt Creator. Is this the proper way of doing things?

我假设你的意思是“包含头文件”:当创建一个带有关联 .ui 的小部件时,你应该在你的小部件类的头文件中包含 uic(在你的情况下由 Qt Creator 创建)生成的头文件,并且那么你有三个选择:

  1. 继承自 uic 生成的类。
  2. 在你的类(class)中持有一个指向所述类(class)的指针。
  3. 将所述类保存在常规成员变量中。

除非 ui 类真的很大,否则我更喜欢数字 3,因为它意味着少一个 new 分配并导致更少耦合。

Inside of the class itself should I be strictly encapsulating data, or making it friendly to like-classes? Does this help with accessability?

您在使用 Qt 时仍应应用 OO 设计规则。我通常将模型放在主窗口内并通过其他小部件他们需要的任何数据,如接口(interface)、容器、结构、委托(delegate)等。有时我会传递整个模型。

Aside from the official book's chapter on MVC, and the on-line tutorial here, what are some other resources to a MVC newcomer in Qt?

通过阅读官方书籍并结合示例使用Qt帮助,我成功地使用了MV。

关于c++ - Qt:Qt 新手问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1671641/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com