QtMvvm  1.1.0
A mvvm oriented library for Qt, to create Projects for Widgets and Quick in parallel
QtMvvm Documentation

Table of Contents

A mvvm oriented library for Qt, to create Projects for Widgets and Quick Controls 2 in parallel.

sample_basic_widgets.gif
Demo Animation Widgets
sample_basic_quick.gif
Demo Animation Quick

For more images, check the Images page

Features

The main feature of QtMvvm is the seperation between ui and logic. With this library, you can create a core library, containing your application logic, as well as ui controllers (called "ViewModels"), and create multiple ui projects on top of it. This way you can for example provide both, a widgets and a qt quick based application, or create different uis for different devices, without having to code anything twice.

The key features are:

QtMvvm Datasync

The QtMvvmDatasync modules help you to integrate QtDataSync (An easy and reliable synchronization library) into your projects. It adds ViewModels and Views to:

The Mvvm Pattern

If you don't know the Mvvm pattern already, you can read up on the links below. It's basically a clever seperation of logic (the models), presentation logic (the viewmodels) and the actual GUI (the views) that is very useful when creating applications that need to support different uis for the same data.

Good links to get started:

Download/Installation

  1. Package Managers: The library is available via:
  2. Simply add my repository to your Qt MaintenanceTool (Image-based How-To here: Add custom repository):
    1. Start the MaintenanceTool from the commandline using /path/to/MaintenanceTool --addTempRepository <url> with one of the following urls (GUI-Method is currently broken, see QTIFW-1156) - This must be done every time you start the tool:
    2. A new entry appears under all supported Qt Versions (e.g. Qt > Qt 5.11 > Skycoder42 Qt modules)
    3. You can install either all of my modules, or select the one you need: Qt Mvvm
    4. Continue the setup and thats it! you can now use the module for all of your installed Kits for that Qt Version
  3. Download the compiled modules from the release page. Note: You will have to add the correct ones yourself and may need to adjust some paths to fit your installation! In addition to that, you will have to download the modules this one depends on as well. See Section "Requirements" below.
  4. Build it yourself! Note: This requires all build an runtime dependencies to be available (See Section "Requirements" below). If you don't have/need cmake, you can ignore the related warnings. To automatically build and install to your Qt installation, run:
    • qmake
    • make qmake_all
    • make (If you want the tests/examples/etc. run make all)
    • Optional steps:
      • make doxygen to generate the documentation
      • make lrelease to generate the translations
    • make install

Requirements

The library only has a few dependencies. The main modules only depends on qtbase and qtquick respectively. However, the Datasync extensions need QtDataSync of course.

Modules

Usage

The following chapters will explain how to create a QtMvvm Project and how to correctly implement applications with it. A Mvvm Project always consists of one core project, with the application logic, and one or more gui projects with the View implementations. In the following section it is explained how to use QtMvvm without going into the depths. For more details you can check the sample projects. If you want to go deeper on how the Framework works and what detailed steps are needed, check out the Documentation of the following classes:

The easiest way to create a QtMvvm Project is to use the provided project template. If you did not install via a package manager or the repository, follow the steps below to add the wizard.

Add the custom wizard

If you did install the module as module you can skip this part. To create a new QtMvvm project, you can use a custom wizard for QtCreator. You will have to add it to your computer once. To do this, you will have to copy the contents of the [ProjectTemplate](ProjectTemplate) folder to a location known by QtCreator (Pro Tip: Use Kinolien's Gitzip to download that directory only). The locations can be found here: Locating Wizards. If you are, for example, working on linux, create a new folder called QtMvvm inside of $HOME/.config/QtProject/qtcreator/templates/wizards and copy the contents there. After restarting QtCreator, the project template should appear in the Applications section of the new-dialog as QtMvvm Application Project.

Create and initialize the QtMvvm Project

Follow the setup to create the project. You can select the GUI-frontends you want to use, as well as additional features. After that you get a basic project skeleton with a simple CoreApp and a ViewModel, as well as the corresponding views.

For more Details on these classes, check the Documentation.

Adding new ViewModels and Views

The most important part is to know how to add new ViewModels and Views.

Create the ViewModel

Create the View for QtWidgets

Create the quick ui

Understanding how QtMvvm works

The general idea is the following: You create viewmodels in your core project, which represent uis. They typically contain all the properties relevant for the ui, methods (slots) that can be called (e.g. on a button click) and signals to inform the ui about changes and other events. Thus, you can use the as ui "placeholders". Of course, They only contain the ui logic, not the actual uis.

The CoreApp is what's reponsible for managing those viewmodels. Showing a viewmodel, as well as messages (alert dialogs) are all controlled by the coreapp. The coreapp uses a so called presenters to create the actual uis. The presenters are located in the ui projects and they are the most complicated part. Their main task is to find ui implementations for viewmodel (called views), and manage the life cycle as well as the presentation of those real views. The presenters are where the decision is made, how a specific view should be shown.

The views are whatever you need to create actual uis. This depends on the presenter used, since the presenter selects the views. Each ui type has their own way to create those views, but they all have in commmon that the views themselves do not control the application. When a viewmodel gets shown, a new view is created and the viewmodel passed to it. Once the views was closed, the view and the viewmodel get deleted again. Views and ViewModels are temporary and should only use the viewmodel to interact with other parts of the application.

A side note on presenters

To create a presenter, the QtMvvm::IPresenter must be implemented and provided via the ServiceRegistry. Presenters can become quite complicated, but they are the thing you need to modify if you want to present views in a different way from the ones supported. Currently, the presenters can do the following:

Icons

In many of the UI projects default icons are used for the views (if no icon theme is present). They are taken from: