Privacy policyContactsAbout siteOpinionsGitHubDonate
© EVILEG 2015-2018
Recommend hosting

Qt WinAPI - Lesson 004. QtIFW - Automation WinDeployQt and build installers with Qt Installer Framework

Qt, Qt Installer Framework, QtIFW, windeployqt

Correct programmer - it is a lazy programmer. If you can automate something, you definitely need to do this. For example, it can be run automatically with the collecting windeployqt online and offline installers, as well as the preparation of the application repository using Qt Installer Framework and black magic QMake .

In order to make the most beautiful way, it is necessary that the project has been organized by the structure of the subdirs, that is comprised of several projects. We do not need every time you build the project to create installers. Therefore, the project will be a separate installer.

But automation windeployqt leave in the main project.

Project structure

So, we have a project with two sub-projects:

  1. - application project
  2. -  installer project

The main project is the most usual "Hello world", but the biggest interest is in the script QMake, which is responsible for windeployqt applications.

The second project has a minimal structure to build online and offline installers, as well as build the repository. QMake script in the profile of the project also includes the necessary information for the assembly automation installers.

Automation WinDeployQt

This file is the traditional content for subdirs project.

TEMPLATE = subdirs

CONFIG += ordered

    Hello \

In addition to the usual instructions executable assembly directories, and other output files in the project, the script is executed QMake launch windeployqt utility.

QT += core
QT -= gui

CONFIG += c++11

TARGET = Hello
CONFIG += console
CONFIG -= app_bundle


# Select the executable assembly directory depending on project build mode
CONFIG(debug, debug|release) {
    DESTDIR = $$OUT_PWD/../../HelloDebug
} else {
    DESTDIR = $$OUT_PWD/../../HelloRelease
# separate directories on the output project files
MOC_DIR = ../common/build/moc
RCC_DIR = ../common/build/rcc
UI_DIR = ../common/build/ui
unix:OBJECTS_DIR = ../common/build/o/unix
win32:OBJECTS_DIR = ../common/build/o/win32
macx:OBJECTS_DIR = ../common/build/o/mac

# depending on the project's build mode
# run win deploy the application in the target directory, that is, collect all the dll
CONFIG(debug, debug|release) {
    QMAKE_POST_LINK = $$(QTDIR)/bin/windeployqt $$OUT_PWD/../../HelloDebug
} else {
    QMAKE_POST_LINK = $$(QTDIR)/bin/windeployqt $$OUT_PWD/../../HelloRelease

SOURCES += main.cpp

If an assembly-executable folder is clear, then we shall understand that the same thing happens when the windeployqt.

QMAKE_POST_LINK - This directive specifies the action after completion of the project build. That is what we do after the executable file was compiled.

$$(QTDIR) - variable that contains the path to Qt assembly kit. In my case it D:\Qt\5.7\mingw53_32.

To perform windeployqt not necessarily indicate sufficient to indicate an executable file as an argument to the folder where the file is. As a result, the project completion of the assembly, it will automatically collecting the necessary dll for application , and they will be placed near the executable file.

Build installers and Repository

Build installers and online project repository is done using Qt Installer Framework, which contains in its composition utility is to build installers themselves, and for the preparation of the application repository.

To building the two utilities from this framework will be used:

  • binarycreator - utility to build the installer;
  • repogen - a utility to prepare online repository.

Before we deal with QMake script, examine the configuration files and the directory structure to build installers.

Directory structure

Consider the structure of the project:

  • config - which is the configuration file of the installer:
    • config.xml - in this file will contain information about the remote repository, version, project name, etc.
  • packages - which will be in packages, which will be collected in installers, for example:
    • ru.evileg.helloinstaller - directory of the first package
      • meta - directory that contains installation scripts that will describe the specific functionality, such as the closing of the active instance of the application, if the application is updated, or prescribing information in the system registry.
        • package.xml - the minimum version required the presence of the file, which will be described in the draft version and build date. This information is required for the formation of Updates.xml file that will be placed in the online repository.
      • data - in this directory will be necessary to put the executable file and all necessary the dll, resource files, transfer files, etc. That is all that is needed to build a working application.
    • ru.evileg.ecolor -  as well as, for example, the directory with the contents of the second package, which is similar in structure to the previous versions.


The file, which describes the service information about the publisher, application installation paths, and his version of the title. And also contains information about the address of the remote repository. This information will be the same as for the online installer, and for offline installer. After all, we will have among other things more and update the app, so both versions of installers looking for information about a remote repository.

<?xml version="1.0" encoding="UTF-8"?>
    <Name>Hello Installer</Name>
    <Title>1.0.0 Installer</Title>
    <TargetDir>@RootDir@Program Files (x86)\EVILEG\HelloInstaller</TargetDir>
  • Installer
    • Name - Name of application
    • Version - application version
    • Title - Title installer window
    • Publisher - Publisher
    • StartMenuDir - It indicates a product group that owns the application in the start menu of Windows.
    • TargetDir - application installation folder; @RootDir@ - root folder. In this case C:\
      • AllowSpaceInPath - allow spaces in the path to the directory
    • RemoteRepositories - repository list
      • Repository - one of the online repository, there may be several, or they may even be replaced
      • Url - repository address


There have indicated more information about installing the application in order, that is, the existence of certain forms of windows, installation of scripts, for example, for entering information into the registry. It also adds information about the application release date, which will also be placed in Updates.xml file.

This file must be contained in each package. The installer can provide the ability to install a number of components, remember Qt installer, there are a lot of points. Accordingly, any such package is your point.

<?xml version="1.0" encoding="UTF-8"?>
    <DisplayName>Hello Installer</DisplayName>
    <Description>The main component</Description>
  • DisplayName - component name. Required tag.
  • Description - description of the component. Required tag.
  • Version - component version. Required tag.
  • ReleaseDate - Release date. Required tag.
  • Default - the default selection component that is selected the option to install or not.
  • Name - a packet identifier of a domain name. Required tag.
  • ForcedInstallation - It indicates that the component is required for the installation and the user can not exclude it from the installation
  • RequiresAdminRights - It indicates that the package must be installed with administrator rights. The field is optional. And the most interesting thing is that in the process installer may lose data administrator rights. That is, for some of the actions will need to re-ask the user administrator rights.

Here is a version of an assembly installers in separate folders for Release and Debug versions. As well as the repository for the preparation Release versions.

To build the offline installer use binarycreator utility with the following options:

  • --offline-only - as is evident from the name, it indicates that collect offline installer
  • -c - It specifies the path to the configuration file
  • -p - It specifies the path to the folder with the packages, while working QtIFW he will understand so as to form in the installer package with regard to their configuration files and scripts from a meta directory

Note. For the online version of the installer all the same, only the argument --offline-only replaced by --online-only.

A repository for training use utility repogen, with the following parameters:

  • -p - indicates the folder with the packages
  • -i - Specifies the package to be included in the installer
  • -update - It points out that the need to update the repository in the following path. If no repository, the new one will be created in this way.
# Before run make project, need to put executable file and dlls into
# $$PWD/installer/packages/ru.evileg.helloinstaller/data


# Depending on the build mode, determine where it will be collected in installers
CONFIG(debug, debug|release) {
    INSTALLER_OFFLINE = $$OUT_PWD/../../InstallerDebug/Hello.offline
    INSTALLER_ONLINE = $$OUT_PWD/../../InstallerDebug/
    DESTDIR_WIN = $$PWD/packages/ru.evileg.helloinstaller/data
    DESTDIR_WIN ~= s,/,\\,g
    PWD_WIN = $$OUT_PWD/../../HelloDebug
    PWD_WIN ~= s,/,\\,g

    copydata.commands = $(COPY_DIR) $$PWD_WIN $$DESTDIR_WIN
    first.depends = $(first) copydata
    QMAKE_EXTRA_TARGETS += first copydata
} else {
    # set variables that will contain the path name to the installers
    INSTALLER_OFFLINE = $$OUT_PWD/../../InstallerRelease/Hello.offline
    INSTALLER_ONLINE = $$OUT_PWD/../../InstallerRelease/

    # set a variable that should contain the path to the data folder
    DESTDIR_WIN = $$PWD/packages/ru.evileg.helloinstaller/data
    DESTDIR_WIN ~= s,/,\\,g
    # set all the path from the application to the DLL need to copy
    PWD_WIN = $$OUT_PWD/../../HelloRelease
    PWD_WIN ~= s,/,\\,g

    # First, you want to compile installers, you must copy the files from 
    # the output folder of the project together with all DLL 
    # in the data folder, which refers to build packages
    copydata.commands = $(COPY_DIR) $$PWD_WIN $$DESTDIR_WIN
    first.depends = $(first) copydata
    # Asking a custom build target, at which the first fulfill kompirovanie files, 
    # and then, and the rest that follows the script QMake
    QMAKE_EXTRA_TARGETS += first copydata

# Create the target assembly Offline Installer
INPUT = $$PWD/config/config.xml $$PWD/packages
offlineInstaller.depends = copydata
offlineInstaller.input = INPUT
offlineInstaller.output = $$INSTALLER_OFFLINE
offlineInstaller.commands = $$(QTDIR)/../../QtIFW2.0.3/bin/binarycreator --offline-only -c $$PWD/config/config.xml -p $$PWD/packages ${QMAKE_FILE_OUT}
offlineInstaller.CONFIG += target_predeps no_link combine

QMAKE_EXTRA_COMPILERS += offlineInstaller

# Create the target assembly Online Installer
INPUT = $$PWD/config/config.xml $$PWD/packages
onlineInstaller.depends = copydata
onlineInstaller.input = INPUT
onlineInstaller.output = $$INSTALLER_ONLINE
onlineInstaller.commands = $$(QTDIR)/../../QtIFW2.0.3/bin/binarycreator --online-only -c $$PWD/config/config.xml -p $$PWD/packages ${QMAKE_FILE_OUT}
onlineInstaller.CONFIG += target_predeps no_link combine

QMAKE_EXTRA_COMPILERS += onlineInstaller

# the repository will only be collected in the case of release mode
CONFIG(release, debug|release) {
    # The assembly of the repository is made after it has been collected Installers
    # For this we use QMAKE_POST_LINK instead QMAKE_EXTRA_COMPILERS
    # Since it is well suited for this
    QMAKE_POST_LINK += $$(QTDIR)/../../QtIFW2.0.3/bin/repogen -p $$PWD/packages -i ru.evileg.helloinstaller --update $$OUT_PWD/../../repository

    packages/ru.evileg.helloinstaller/meta/package.xml \

Download the file to the project Qt Installer Framework example


Virtual hosting with 10 percent discount
Virtual hosting with 10 percent discount
EVILEG offers reliable hosting with a 10% discount for virtual hosting and 5% for VPS

Очень полезная статья. Спасибо большое! Но у меня осталась пара вопросов. Я новичок в QT и не все понятно. Поэтому вопросы будут дилетантские. У Вас уже был создан проект с поддиректориями (это правильно?) включающий в себя проект программы и проект инсталлятора. Для проекта программы, как я понимаю, может при создании быть выбран любой шаблон. А вот, чтобы создать проект инсталлятора, какой должен шаблон необходимо выбрать? Второй вопрос. Вы рассказали про структуру файлов в проекте. Это все понятно. А вот какова должна быть структура файлов на диске. Есть корневой проект HelloInstaller, есть папка HelloInstaller. Есть два подпроекта: Hello и Installer. Так вот вопрос, папки этих проектов должны быть расположены внутри HelloInstaller, рядом с ним, или в любом другом месте? Подозреваю, что можно по разному. Но, на Ваш взгляд, как правильно? Заранее спасибо за ответ!

Да. За основу был взят проект с поддиректориями.

Я не нашёл подходящего шаблона проекта для инсталлятора, поэтому взял пустой проект qmake и уже переписал его для инсталлятора.

Вот как выглядит структура проекта, так и располагаются файлы и папки на диске. То есть есть общая папка HelloInstaller, а в ней уже папки проектов Hello и Installer, а также Да, можно, конечно, по-разному. Но не вижу смысла раскидывать подпроекты повсюду, если есть возможность держать всё в одной папке. Будете использовать git-репозиторий, то заметите, что это удобно. Конечно, третьесторонние библиотеки могут располагаться и в другом месте, особенно если они используются в другом проекте, никак не связанном с текущим проектом. Но по-максимуму всё располагайте в одном месте.


Огромное спасибо за быстрый ответ.

Пожалуйста. Будут ещё вопросы, спрашивайте. Только задавайте их на форуме , чтобы были отдельные ветки обсуждений.


Only authorized users can post comments.
Please, Log in or Sign up
March 18, 2019, 3:12 p.m.
Пётр Махнёв

C ++ - Test 004. Pointers, Arrays and Loops

  • Result:50points,
  • Rating points-4
March 18, 2019, 7:59 a.m.
Ян Греку

C++ - Тест 003. Условия и циклы

  • Result:21points,
  • Rating points-10
March 15, 2019, 4:32 p.m.
Михаил Дементьев

C++ - Test 001. The first program and data types

  • Result:60points,
  • Rating points-1
Last comments
March 16, 2019, 1:55 p.m.

Спасибо за статью. Давно итересует следующий вопрос: с помощью переменных QMAKE_TARGET_COMPANYQMAKE_TARGET_PRODUCTQMAKE_TARGET_DESCRIPTIONможно задать свойства компилируемой программы, о...
March 12, 2019, 10:19 a.m.
Jean Stefanovich

Большое спасибо за разъяснения!
March 12, 2019, 10:04 a.m.
Евгений Легоцкой

Hello, In fact, this functionality or is not implemented, or is not documented. I'm not sure. But I think, that it should be implemented in Text QML Type. Because of we can write text in...
March 12, 2019, 9:51 a.m.
Евгений Легоцкой

Да вы правы. На самом деле проще через QSqlQueryModel, сколько не пытался использовать эти дженерики типо QSqlTableModel и QSqlRelationalTableModel, то всегда упирался в какие-то их ограничени...
March 12, 2019, 9:47 a.m.
Jean Stefanovich

Единицы измерения лежат там же где и названия продуктов. Просто в таблице ингредиенты нет ещё одного столбца, на который можно было бы установить setRelation. Я в итоге в базе создал ещё один ...
Now discuss on the forum
March 17, 2019, 10:47 p.m.
Евгений Легоцкой

Добрый день. Вот, нашлось у меня немного времени. Делается это через шаблон проектирования наблюдатель.
March 15, 2019, 9:52 p.m.
Чарльз Грин

спасибо, попробую, отпишусь
March 15, 2019, 7:41 p.m.

Сори догадался)
March 12, 2019, 4:57 p.m.

Большооооое спасибо!!!!!Не передать как я вам благодарен, спасибо что всегда отзываетесь.Теперь я смогу продолжить работу в QT!!! (пробую писать бота (Я как вы могли догадаться немного не пр...
March 12, 2019, 1:20 p.m.

Ну так если у вас есть готовая программа так ей и воспользуйтесь. Вы же написали ее вот и пользуйтесь.
Join us in social networks

For registered users on the site there is a minimum amount of advertising