Creating a simple M/V application with Qt Quick
In earlier sections, we discussed Qt's Model-View-Delegate framework. You learned how to create a custom Model and delegate and how to use a C++ Model. But you must be wondering how to integrate with our QML frontend. In this section, we will create a C++ Model and expose it to the QML engine. We will also discuss how to register a custom Model as a QML type.
Let's create an application that fetches a Model from the C++ code and displays it in a Qt Quick-based application:
#include <QGuiApplication> #include <QQmlApplicationEngine> #include <QQmlContext> #include <QStringListModel> int main(int argc, char *argv[]) { QGuiApplication app(argc, argv); QQmlApplicationEngine engine; QStringList stringList; stringList << "Item 1" << "Item 2" << "Item 3" ...