Creating a simple Qt Widgets application using the M/V pattern
It is time for us to create a simple example using Qt Widgets. The example in this section illustrates how a predefined QFileSystemModel
is used in association with the built-in QListView
and QTreeView
widgets. Delegation is automatically taken care of when the Views are double-clicked.
Follow these steps to create a simple application that implements the M/V pattern:
- Create a new project using Qt Creator, selecting the Qt Widgets template from the project creation wizard. It will generate a project with a predefined project skeleton.
- Once the application skeleton is created, open the
.ui
form and addQListView
andQTreeView
to the form. You may add two labels to distinguish the Views as shown here: - Open the
mainwindow.cpp
file and add the following contents:#include "mainwindow.h" #include "ui_mainwindow.h"...