Models and Views

The Model-View pattern describes techniques of separating the underlying data (the model) from the class that presents the user with a GUI (the view). In this chapter we will see a model for a form, and a couple of ways to view and enter data into it. Qt model and view classes are discussed, and we will see examples of lists, trees, and tables.


M-V-C: What about the Controller?



Dynamic Form Models



Qt 4 Models and Views



Table Models



Tree Models


In several earlier examples we saw code that maintained a clean separation between model classes that represent data and view code that presents a user interface. There are several important reasons for enforcing this separation.

First of all, separating model from view reduces the complexity of each. Model code and view code have completely different maintenance imperativeschanges are driven by completely different factorsso it is much easier to maintain each of them when they are kept separate. Furthermore, the separation of model from view makes it possible to maintain several different, but consistent, views of the same data model. The number of sophisticated view classes that can be reused with well-designed models is constantly growing.

Some older GUI toolkits offer lists, trees, and tables, but they require the developer to store model data inside them. Storing data inside view classes leads to a strong dependency between the user interface and the underlying data model. This dependency makes it very difficult to reuse the view classes.

M V C What about the Controller?

Part I: Introduction to C++ and Qt 4

C++ Introduction


Introduction to Qt



Inheritance and Polymorphism

Part II: Higher-Level Programming


Introduction to Design Patterns


Generics and Containers

Qt GUI Widgets


Validation and Regular Expressions

Parsing XML

Meta Objects, Properties, and Reflective Programming

More Design Patterns

Models and Views

Qt SQL Classes

Part III: C++ Language Reference

Types and Expressions

Scope and Storage Class

Statements and Control Structures

Memory Access

Chapter Summary

Inheritance in Detail

Miscellaneous Topics

Part IV: Programming Assignments

MP3 Jukebox Assignments

Part V: Appendices

MP3 Jukebox Assignments


MP3 Jukebox Assignments

An Introduction to Design Patterns in C++ with Qt 4
An Introduction to Design Patterns in C++ with Qt 4
ISBN: 0131879057
EAN: 2147483647
Year: 2004
Pages: 268 © 2008-2020.
If you may any questions please contact us: