Qt 项目结构 - 需要建议
我目前正在开发一个基于 Qt4/QtCreator 的项目。我想向您寻求有关如何组织我的申请的建议。
共有 3 个独立的工具,每个工具都有自己的视图。所有视图都作为不可关闭的选项卡集成在主窗口中。我准备了 3 个视图:Tool1View、Tool2View、Tool3View
每个工具都假设执行由用户操作触发的某些任务。但这些不是与数据库相关的操作(列表/添加/修改...) - 至少用户不会在 gui 元素中添加/修改/列出记录。
我正在考虑在 2 个类中实现每个工具:
第一个类 ToolXView 实现小部件以及与 gui 更改相关的所有任务。
第二类 ToolX 实现应用程序逻辑。该类的成员函数由View类触发。每当此类必须更新 GUI 元素时,它都会调用 View 类中的专用函数。因此,这里不会直接调用小部件。
视图类和逻辑类将相互链接以允许两种方式通信。
现在我想知道这是否是一个好方法。请根据您的经验给我建议。
我计划将指向逻辑类的指针封装为视图类的属性,并将指向视图类的指针封装为逻辑类的属性。这样我计划将它们集成起来。
我应该使用信号/槽来提供通信还是只调用成员函数?
我必须在 QtSql 数据库中存储一些数据。我应该提供一个单独的类用于数据库访问吗?或者只是在 Logic 类中实现单独的成员函数?
你如何命名你的类。这个方案好还是我应该改变它?
感谢您的帮助。我很欣赏你的评论。
I'm currently working on a project based on Qt4/QtCreator. I'd like to ask You for advice on how to organize my application.
There are 3 seperate tools, each has it's own view. All views are integrated in main window as non-closable tabs. I've prepare 3 views: Tool1View, Tool2View, Tool3View
Each tool is suppose to perform some task triggered by user actions. But these are not database related operations (list/add/modify...) - at least the user is not going add/modify/list records in gui elements.
I am thinking to implement each tool in 2 classes:
First class ToolXView implementing the widget and all tasks related to gui changes.
Second class ToolX implementing application logic. Member functions of this class are triggered by View class. Whenever this class has to update GUI elements it cals specialised functions in View class. So no direct calls to widgets are made from here.
View class and logic class will be linked with each other to allow 2 way communication.
Now I'm wondering if this is a good way to go. Please advice me based on Your experience.
I'm planning to encapsulate pointer to logic class as a property of a view class and pointer to view class as a property of logic class. This way I plan to integrade them.
Should I use signals/slots to provide comuncation or just call member functions ?
I'll have to store some data in QtSql database. Should I provide a seperate class for database access. Or just implement sepereate member function inside Logic class ?
How do You name Your classes. Is this scheme good or should I change it ?
Thanks for help. I appreciate your comments.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用 mvc 架构非常棒。
1& 2 - 在上面的链接中,您将看到 mvc 架构的 UML 图。关于它,我会将视图信号连接到控制器方法,然后从控制器调用视图方法。
3 - 关于数据库访问,我会在您的架构中添加一个专门用于数据访问的数据访问部分。您可以有一个接口来定义数据访问对象签名,然后在数据库的专用类中实现它(这样您就可以更改数据位置而无需修改整个应用程序)。
4 - 你的类命名看起来不错。但我会更进一步并调用类:
希望有帮助
Using the mvc architecture is great.
1 & 2 - In the link above you will see the UML diagram of a mvc architecture. Regarding it, I would connect view signals to controller methods and then call a view method from controller.
3 - Regarding Database access I would add a Data Access part in your architecture which is specialized to the data access. You can have an interface to define the data access object signature and then implement it in a specialized class for database (So you will be able to change data location without modifying the whole application).
4 - You class naming seems good. But I would go further and call classes:
Hope that helps