Converting UI Projects to Applications

Qt Quick UI projects are useful for creating user interfaces. To use them for application development in Qt Creator you have to add:

  • Project configuration file (.pro)
  • C++ code (.cpp)
  • Resource files (.qrc)
  • Code needed for deploying applications to devices

You can use a Qt Creator wizard to create a Qt Quick application that is built using the qmake build system and then copy the source files from the Qt UI Quick project to the application project.

You can use the RESOURCES option in the project configuration file to automatically add all the QML files and related assets to a Qt resource file.

The wizard automatically adds the QML_IMPORT_PATH option to the project file for specifying the required QML import path. The path is only needed if more than one subdirectory contains QML files.

Then you can use the QQuickView class in the main C++ source file to show the main QML file when the application starts.

At the time of this writing, the Qt Quick Timeline module is delivered with Qt Design Studio, but not with Qt. If you use a timeline in a Qt Design Studio project that you import to Qt Design Studio, you must build the Qt Quick Timeline module and install it to your Qt to be able to build your project.

Converting Projects

To convert a project that has a .qmlproject file to one that has a .pro file:

  1. Select File > New File or Project > Application > Qt Quick Application - Empty > Choose.
  2. In the Build system field, select qmake as the build system to use for building and running the project, and then select Next (or Continue on macOS).
  3. Follow the instructions of the wizard to create the project.
  4. In the file explorer, copy the source files from the Qt Quick UI project directory to a subdirectory in the application project directory. For the purpose of these instructions, the directory is called qml.
  5. Open the application project file, and edit the value of the RESOURCES option to add the following line:
    RESOURCES += \
        $$files(qml/*)
  6. Select Build > Run qmake to apply the RESOURCES option to the build configuration.
  7. Open the main.cpp file and replace the QQmlApplicationEngine object with a QQuickView object:
        QQuickView view;
        view.setSource(QUrl("qrc:/qml/ProgressBar.ui.qml"));
        if (!view.errors().isEmpty())
            return -1;
        view.show();

    Where qml\main.qml is the path to and the name of the main QML file in the Qt Quick UI project.

  8. Select Build > Run to build and run your project.

For example, if you copy the source files of the ProgressBar example from your Qt Design Studio installation (located in the \share\qtcreator\examples\ProgressBar directory) to an empty Qt Quick application project and make the necessary changes, the main.cpp file should look as follows:

#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QQuickView>

int main(int argc, char *argv[])
{
    QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);

    QGuiApplication app(argc, argv);

    QQuickView view;
    view.setSource(QUrl("qrc:/qml/ProgressBar.ui.qml"));
    if (!view.errors().isEmpty())
        return -1;
    view.show();

    app.exec();
}

Adding Qt Quick Timeline Module to Qt Installations

Check out the Qt Quick Timeline module from Qt Code Review.

For example:

git clone ssh://user@codereview.qt-project.org:29418/qt/qtquicktimeline

Then use qmake from your Qt installation to build the module and to add it to your Qt. Switch to the directory that contains the sources (usually, qtquicktimeline), and enter the following commands:

<path_to_qmake>\qmake -r
make
make install

On Windows, use the nmake and nmake install commands instead.

Available under certain Qt licenses.
Find out more.