Qt: a framework for writing graphic applications in C++, also Python
Qt was developed by Norwegian programmers in the early 1990s. It is now being developed by The Qt Company and The Qt Project as a union of companies and individuals working to promote Qt. The Qt Project follows the open-source governance philosophy, and all members can take part in the decision-making process aimed at improving the framework.
Installing Qt
Installing Qt on Ubuntu
You need to install packages:
sudo apt install -y qtcreator qtbase5-dev qt5-qmake cmake
Recommended: cmake-doc
Warning These packages would take up about 1GB space on your hard disk.
Qt Core
(From https://doc.qt.io/qt-6/qtcore-index.html)
The Qt Core module adds these features to C++:
- a very powerful mechanism for seamless object communication called signals and slots
- queryable and designable object properties
- hierarchical and queryable object trees that organize object ownership in a natural way with guarded pointers (QPointer)
- a dynamic cast that works across library boundaries
Model/View Programming
(From https://doc.qt.io/qt-6/model-view-programming.html)
Qt contains a set of item view classes that use a model/view architecture to manage the relationship between data and the way it is presented to the user. The separation of functionality introduced by this architecture gives developers greater flexibility to customize the presentation of items, and provides a standard model interface to allow a wide range of data sources to be used with existing item views. In this [section], we give a brief introduction to the model/view paradigm, outline the concepts involved, and describe the architecture of the item view system. Each of the components in the architecture is explained, and examples are given that show how to use the classes provided.
The model/view architecture
Model-View-Controller (MVC) is a design pattern originating from Smalltalk that is often used when building user interfaces. In Design Patterns, Gamma et al. write:
MVC consists of three kinds of objects. The Model is the application object, the View is its screen presentation, and the Controller defines the way the user interface reacts to user input. Before MVC, user interface designs tended to lump these objects together. MVC decouples them to increase flexibility and reuse.
If the view and the controller objects are combined, the result is the model/view architecture. This still separates the way that data is stored from the way that it is presented to the user, but provides a simpler framework based on the same principles. This separation makes it possible to display the same data in several different views, and to implement new types of views, without changing the underlying data structures. To allow flexible handling of user input, we introduce the concept of the delegate. The advantage of having a delegate in this framework is that it allows the way items of data are rendered and edited to be customized.
The model communicates with a source of data, providing an interface for the other components in the architecture. The nature of the communication depends on the type of data source, and the way the model is implemented.
The view obtains model indexes from the model; these are references to items of data. By supplying model indexes to the model, the view can retrieve items of data from the data source.
In standard views, a delegate renders the items of data. When an item is edited, the delegate communicates with the model directly using model indexes.
Generally, the model/view classes can be separated into the three groups described above: models, views, and delegates. Each of these components is defined by abstract classes that provide common interfaces and, in some cases, default implementations of features. Abstract classes are meant to be subclassed in order to provide the full set of functionality expected by other components; this also allows specialized components to be written.
Models, views, and delegates communicate with each other using signals and slots:
- Signals from the model inform the view about changes to the data held by the data source.
- Signals from the view provide information about the user's interaction with the items being displayed.
- Signals from the delegate are used during editing to tell the model and view about the state of the editor.
Model/View Tutorial
(From https://doc.qt.io/qt-6/modelview.html)
Table, list and tree widgets are components frequently used in GUIs. There are 2 different ways how these widgets can access their data. The traditional way involves widgets which include internal containers for storing data. This approach is very intuitive, however, in many non-trivial applications, it leads to data synchronization issues. The second approach is model/view programming, in which widgets do not maintain internal data containers. They access external data through a standardized interface and therefore avoid data duplication. This may seem complicated at first, but once you take a closer look, it is not only easy to grasp, but the many benefits of model/view programming also become clearer.
User Interfaces
(From https://doc.qt.io/qt-6/topics-ui.html)
The Qt framework's main user interface technologies are Qt Quick and Qt Widgets. Qt Quick interfaces are fluid, dynamic, and are best on touch interfaces. Qt Widgets are for creating complex desktop applications. You can create Qt Quick and Qt Widgets interfaces with the target platform's native look and feel.
Building UIs with Qt Quick
Qt Quick is for creating dynamic and fluid user interfaces. The Qt Quick Controls module supplies QML types such as buttons, dialogs, and menus. You can use QML, a declarative language, to build the UI and JavaScript to implement the logic.
Qt Widgets User Interfaces
Qt Widgets are the user interface elements that are typical in desktop environments. The widgets integrate well to the underlying platform providing native look and feel on Windows, Linux and macOS. The widgets are mature and feature rich user interface elements suitable for mostly traditional user interfaces. In contrast to Qt Quick, the widgets are for creating large desktop applications and less suited for creating touch-centric applications with fluid interfaces.
Qt Creator
(From https://github.com/qt-creator/qt-creator)
Qt Creator is a cross-platform, integrated development environment (IDE) for application developers to create applications for multiple desktop, embedded, and mobile device platforms.
The Qt Creator Manual is available at: https://doc.qt.io/qtcreator/index.html
For an overview of the Qt Creator IDE, see https://doc.qt.io/qtcreator/creator-overview.html
Supported Platforms The standalone binary packages support the following platforms:
- Windows 10 (x86_64) or later
- Windows 11 (ARM64) or later
- (K)Ubuntu Linux 22.04 (x86_64) or later
- (K)Ubuntu Linux 24.04 (arm64) or later
- macOS 13 or later
When you compile Qt Creator yourself, the Qt version that you build with determines the supported platforms.