一个面向 MVVM 的 Qt 库,用于同时创建 Widgets 和 Quick 项目
A mvvm oriented library for Qt, to create Projects for Widgets and Quick Controls 2 in parallel.
For more images, check the Images page
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:
The QtMvvmDatasync modules help you to integrate QtDataSync (An easy and reliable synchronization library) into your projects. It adds ViewModels and Views to:
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:
qt5-qtmvvmlibqt5mvvm[1/-dev]brew tap Skycoder42/qt-modulesqtmvvmsource /usr/local/opt/qtmvvm/bashrc.sh before you can use the module. Some goes for the qtdatasync dependency./path/to/MaintenanceTool --addTempRepository with one of the following urls (GUI-Method is currently broken, see QTIFW-1156) - This must be done every time you start the tool:
Qt > Qt 5.11 > Skycoder42 Qt modules)Qt Mvvmqmakemake qmake_allmake (If you want the tests/examples/etc. run make all)make doxygen to generate the documentationmake lrelease to generate the translationsmake installThe library only has a few dependencies. The main modules only depends on qtbase and qtquick respectively. However, the Datasync extensions need QtDataSync of course.
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.
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 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.
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.
Important: Due to QTBUG-69963, you must always link to QtMvvmQuick when creating a QtQuick application for windows (See Issue #1). Since windows optimizes library and only links them if referenced at least once, simply add the line
QtMvvm::QuickPresenter::getInputViewFactory(); //Workaround for QTBUG-69963to your main.cpp and it should work as expected
The most important part is to know how to add new ViewModels and Views.
QtMvvm::ViewModelQ_INVOKABLE MyClass(QObject *parent);examples/mvvmcore/SampleCore/sampleviewmodel.h for an example ViewModelMyCustomViewModel, the widgets name must start with MyCustom as well (e.g. MyCustomWindow, MyCustomDialog, MyCustomView, etc.)Q_INVOKABLE MyCustomWindow(QtMvvm::ViewModel *viewModel, QWidget *parent = nullptr);MyCustomViewModel *_viewModel;viewModel to your viewmodel class and assign it to _viewModelWidgetPresenter::registerView(); to your main.cpp, before calling QApplication::execexamples/mvvmwidgets/SampleWidgets/sampleview.h for an example widgetqmlRegisterUncreatableType("com.example.mvvmexample", 1, 0, "MyCustomViewModel", "ViewModels cannot be created!"); to your main cpp before creating the engine.:/qml/views (This is required to automatically find the view).MyCustomViewModel, the views name must start with MyCustom as well (e.g. MyCustomView, MyCustomActivity, etc.)import QtQuick 2.10
import QtQuick.Controls 2.3
import de.skycoder42.QtMvvm.Core 1.1
import de.skycoder42.QtMvvm.Quick 1.1
import com.example.mvvmexample 1.0 //adjust to the module defined in your main.cppproperty MyCustomViewModel viewmodel: null (If you did not register the viewmodel, use var instead of MyCustomViewModel as property type)PresenterProgress {}examples/mvvmquick/SampleQuick/SampleView.qml for an example viewThe 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
暂无开放 Issues,或尚未同步最近议题。