user5585984
user5585984

Reputation:

Model View Controller in Qt application development

What is the point behind the MVC pattern? When it is recommended to use MVC design pattern when designing application, what type of applications? I am using Qt for half a year, and never used MVC, whether I should use it? What other design patterns exist for application design and development?

Upvotes: 0

Views: 1662

Answers (3)

kh25
kh25

Reputation: 1298

Qt makes extensive use of it's own model/view pattern throughout the QtGUI components which is it's interpretation of the MVC pattern.

See here for more details:

http://doc.qt.io/qt-4.8/modelview.html

When should you use it? Ideally wherever possible - especially when dealing with complex GUI components that need to represent large quantities of data. The QTableView is where I make use of it most regularly.

The main advantage it gives you is simple, by loosely coupling your view and your data, changes to one have minimal impact on the other. This makes your code more maintainable in the future.

Upvotes: 0

Mathieu Van Nevel
Mathieu Van Nevel

Reputation: 1486

MVC is the more usual design pattern for the core of GUI applications. The main purpose, like a lot of architecture, is to split logic and data in your code, because it's more easy to read, maintain (you'll find a lot of advantages)...

But there is something a little more specific. MVC standard is to use Observer/Observable pattern, to refresh your views only when your data are updated. Not like a game loop.

About Qt (>= 4.0), you can see here, that MVC is a part of the framework architecture. So you already use it : don't try to reimplement it, just use Qt classes like it was design (see the link above).

You can also extend the architecture with some MVC variant like MVVM, PureMVC....

About other architectures, I love Entity Component System but it's a little too much for small applications. If you want too learn more about Design Pattern in general, this site is a good one (maybe a little old).

Upvotes: 2

CppChris
CppChris

Reputation: 1261

MVC is a pattern used for GUI applications: it ensures that your business logic - within the [M]odel - is separated from your GUI - within the [V]iews. The [C]ontroller makes sure that those two can communicate with each other.

One of the biggest advantages of this decoupling is that your application will stay maintainable. I can tell you from personal experience that applications with one main dialog handling almost everything (db access, user input verification, etc.) are really hard to maintain. Do yourself a favor and stick to clean architectures within your applications as this will pay off later within its life cycle.

Another GUI application pattern would be MVVM and for more information on the topic of application patterns I highly recommend the book "Patterns of Enterprise Application Architecture" by Martin Fowler.

Upvotes: 0

Related Questions