Some workflows in this repository require tokens to function correctly. Below are the details for the required tokens and how to configure them.
The CODECOV_TOKEN is required to upload code coverage reports to Codecov. This token ensures that only authorized users can upload coverage data for your repository.
- Go to your repository on Codecov.
- Navigate to Settings β Repository β Upload Token.
- Copy the generated token.
The Personal Access Token (PAT) is only required for the disabled workflows in this repository. These workflows are kept for reference and are not actively used in the CI/CD pipeline.
- Go to GitHub Personal Access Tokens.
- Click βGenerate new token (classic)β.
- Set a name (e.g.,
Legacy CI Token) and expiration date. - Under Scopes, check:
repo
- Click βGenerate tokenβ and copy the token immediately.
Once you have generated the required tokens, add them as secrets in your GitHub repository:
- Open your repository on GitHub.
- Navigate to: Settings β Secrets and variables β Actions β New repository secret
- Add the following secrets:
- For Codecov:
- Name:
CODECOV_TOKEN - Secret: (paste the Codecov token)
- Name:
- For Disabled Workflows:
- Name:
PAT_TOKEN - Secret: (paste the PAT token)
- Name:
- For Codecov:
Note: The
CODECOV_TOKENis required for thebuild_and_test_linux.ymlworkflow to upload coverage reports. ThePAT_TOKENis only needed for the disabled workflows.
- Code Coverage Graphs
- Description
- Solution Folder Structure
- Configuration
- Supported Platforms
- How to Install and Run
- Translations
- Code Style and Linting
This project is a template for creating QML-based desktop applications. The solution
is divided into two parts: the main project and a test project. By default, only the
main project is built. The test project can be built if desired, controlled by a CMake
boolean variable <PROJECT_NAME>_BUILD_TEST_PROJECT. Additionally, the CMake variable
<PROJECT_NAME>_BUILD_TARGET_TYPE must be set to static_library for the test project
to be executed.
The template includes various classes, models, and services to load and display settings
or translations. Additionally, it is possible to generate documentation for the project
using Doxygen. The template also includes GitHub workflows (CI builds) for both Linux
and Windows.
.
βββ .git # Git repository metadata
βββ .github # GitHub-specific files (CI workflows)
βββ CMake # CMake files used in both the project and tests
βββ Configs # Configuration files for clang-tidy, clang-format, Doxygen, etc.
βββ QML_Project # The main project
β βββ CMake # CMake files specific to the project
β βββ Headers # Header files
β βββ Resources # Resource files
β βββ Sources # Source files
β βββ ThirdParty # CMake files for external dependencies
β βββ CMakeLists.txt # CMake configuration file for the project
β βββ Config.h.in # Configuration header template
β βββ main.cpp # Main application entry point
β βββ resources.qrc # Qt resource file
βββ QML_Project_Tests # Tests for the project
β βββ Headers # Header files for tests
β βββ Sources # Source files for tests
β βββ ThirdParty # CMake files for external dependencies used in tests
β βββ CMakeLists.txt # CMake configuration file for tests
β βββ main.cpp # Main entry point for tests
βββ Scripts # Scripts for building and deploying on various platforms
β βββ Win # Windows-specific scripts
β βββ Linux # Linux-specific scripts
β βββ Mac # Mac-specific scripts
βββ Dockerfile # Dockerfile for building and running the project in a container
βββ .gitignore # Git ignore file
βββ CMakeLists.txt # Top-level CMake configuration file
βββ README.md # Project README file
-
<PROJECT_NAME>_BUILD_TARGET_TYPE: Specifies the type of build for the application. Possible values are:
executabledynamic_librarystatic_library
-
<PROJECT_NAME>_BUILD_TEST_PROJECT: Specifies whether the TestProject should also be built. Default is Off.
-
USE_CLANG_FORMAT: Specifies whether
clang-formatshould be used for code formatting. Default is Off. -
USE_CLANG_TIDY: Specifies whether
clang-tidyshould be used for static analysis. Default is Off. -
CLANG_TOOLS_PATH: Specifies the path to the
clang-formatandclang-tidyexecutables. -
<PROJECT_NAME>_BUILD_DOC: Specifies whether documentation should be generated for the app and/or its test project. The generated documentation is located in the
docfolder within the binary directory, with separate subfolders for the app and the test project. The formatting specifications for the documentation can be centrally configured in the Doxyfile.in file, located in the solution folder. The default setting is Off. -
THIRD_PARTY_INCLUDE_DIR: Specifies where the third-party libraries will be installed. The default path is:
$USERPROFILE/ThirdPartyon Windows$HOME/ThirdPartyon Unix-based systems.
-
SANITIZER_TYPE: Specifies the type of sanitizer to use for the build process. Supported values are:
noneaddressleakmemorythreadaddress_and_leakaddress_and_memorymemory_and_leakaddress_memory_and_leak
Note
Platform-specific notes:
- MSVC supports:
none,address - UNIX supports: all of the above
- QT_DIR: Specifies the path to the Qt 6 installation.
- Windows 10+
- Linux (tested on Ubuntu 24.04.1)
- Mac (tested on macOS Ventura)
- CMake ( Minimum required version 3.19.0 ): Download
- A C++20 compatible compiler (e.g., GCC 10+, Clang 10+, MSVC 19.28+)
- Qt Installer (Qt 6.8): Download
- Optional: Docker (if using the Docker workflow in 6) Using Docker): Download Docker
- Optional: VcXsrv (if displaying the GUI on a Windows host in 6) Using Docker): Download VcXsrv
- Optional: Doxygen (if documentation generation is enabled): Download
- Optional for Doxygen is LaTeX if enabled in
Doxygen.in-File and installed. - Optional:
zipfor creating ZIP archives (ifBUILD_ZIP_ARCHIVEis set totrueinbuild_and_deploy.sh) - Optional:
NSISfor creating installers (ifBUILD_NSIS_INSTALLERis set totrueinbuild_and_deploy.sh) - Optional: Ninja: Required to generate
compile_commands.jsonforclang-tidy. Download Ninja - Optional: clang-format and clang-tidy: To use
clang-formatandclang-tidy, download the appropriate precompiled binary from the LLVM Release Page
Tip
The CMake GUI presents another alternative option to build the project.
Note
All other dependencies are automatically installed by CMake or the respective script.
git clone https://github.com/Dingola/QMLDesktopAppTemplate.git
cd QMLDesktopAppTemplate/
Important
Ensure that the QT_DIR environment variable is set, for example: ..\Qt\6.8.0\msvc2022_64
cmake -B _build -S . -G "Visual Studio 17 2022" -A x64
cd _build
cmake --build . --config Release
cd QMLDesktopAppTemplate/Release/
./QMLDesktopAppTemplate.exe
The project includes scripts for building, testing and deploying the application. These scripts are located in the Scripts directory, organized by platform (e.g., Win for Windows, Linux for Linux).
- build_release.sh: Builds the project in release mode.
- build_and_run_tests.sh: Builds and runs the test project.
- build_and_deploy.sh: Builds and deploys the project. This script can also create a ZIP archive of the deployment directory and/or an NSIS installer using the
installer.nsiscript (Windows only).
To create a ZIP archive of the deployment directory, set BUILD_ZIP_ARCHIVE to true in build_and_deploy.sh.
To create an NSIS installer (Windows only), set BUILD_NSIS_INSTALLER to true in build_and_deploy.sh.
Build the Docker image using the following command:
docker build -t qmldesktopapptemplate-dockerimage .
- Run directly:
docker run qmldesktopapptemplate-dockerimage
- Start an interactive Bash shell:
docker run -it qmldesktopapptemplate-dockerimage bash
- Start the app (virtual display with Xvfb):
Xvfb :99 -screen 0 1920x1080x24 -nolisten tcp & export DISPLAY=:99 "./_build_app_release/QML_Project/QMLDesktopAppTemplate"
- Run the tests (virtual display with Xvfb):
Xvfb :99 -screen 0 1920x1080x24 -nolisten tcp & export DISPLAY=:99 "./_build_tests_release/QML_Project_Tests/QMLDesktopAppTemplate_Tests"
- Download and install VcXsrv Windows X Server: Download VcXsrv.
- Configure VcXsrv:
- Select Multiple windows and set Display number to
99. - Choose Start no client.
- Enable Disable access control.
- Alternatively, use the preconfigured
config.xlaunchfile located in theConfigsfolder of this project. Double-click the file to launch VcXsrv with the correct settings.
- Select Multiple windows and set Display number to
- Start the Docker container:
docker run -it --name QMLDesktopAppTemplate-Container --network host -e DISPLAY=<IP-ADDRESS>:99.0 -e TERM=xterm-256color -e QT_X11_NO_MITSHM=1 QMLDesktopAppTemplate-DockerImage bash
Note
Replace <IP-ADDRESS> with the host's IP address (e.g., 192.168.1.2). Do not use 127.0.0.1 or localhost.
- Inside the container:
- Start the app:
"./_build_app_release/QML_Project/QMLDesktopAppTemplate"
- Run the tests:
"./_build_tests_release/QML_Project_Tests/QMLDesktopAppTemplate_Tests"
- The display number in the
DISPLAYvariable is 99.0, not99. - You can verify this in the VcXsrv logs. Look for a line like:
winClipboardThreadProc - DISPLAY=127.0.0.1:99.0
- Ensure the
DISPLAYvariable is set correctly, e.g.:
export DISPLAY=192.168.1.2:99.0
- Ensure the firewall on the host allows connections to the X11 server (VcXsrv).
- If the GUI does not display, check the
DISPLAYvariable and the VcXsrv logs.
The project includes custom targets for updating and compiling translation files. These targets are defined in the CMake file located in QMLDesktopAppTemplate/QML_Project and can be used to manage translation files located in the QMLDesktopAppTemplate/QML_Project/resources/Translations directory.
Note
The translation files are specified in the CMake file. Initially, only app_de.ts and app_en.ts are included. To support additional languages, you will need to add the corresponding .ts files to the CMake configuration.
To update the translation files, use the following custom target:
_translations_update
To compile the translation files, use the following custom target:
_translations_compile
This project uses clang-format and clang-tidy for code formatting and static analysis.
To use clang-format and clang-tidy, download the appropriate precompiled binary from the LLVM Release Page. Here are the recommended files based on your operating system:
- Windows: clang+llvm-18.1.8-x86_64-pc-windows-msvc.tar.xz
- Linux: clang+llvm-18.1.8-x86_64-linux-gnu-ubuntu-18.04.tar.xz
- macOS: clang+llvm-18.1.8-arm64-apple-macos11.tar.xz
To use clang-format and clang-tidy in your project, you need to set the following options in your CMake configuration:
- USE_CLANG_FORMAT: Enable this option to use
clang-formatfor code formatting. - USE_CLANG_TIDY: Enable this option to use
clang-tidyfor static analysis. - CLANG_TOOLS_PATH: Specify the path to the
clang-formatandclang-tidyexecutables.
To format the C++ code and run static analysis, use the following custom targets:
_run_clang_format_project
_run_clang_tidy_project
To format the C++ code, run the following command after enabling the USE_CLANG_FORMAT option and specifying the path to clang-format:
cmake -DUSE_CLANG_FORMAT=ON -DCLANG_TOOLS_PATH="C:/path/to/clang+llvm-18.1.8-x86_64-pc-windows-msvc/bin" ..
cmake --build . --target _run_clang_format_project
cmake --build . --target _run_clang_format_tests
To run static analysis with clang-tidy, ensure the USE_CLANG_TIDY option is enabled and the path to clang-tidy is specified:
cmake -DUSE_CLANG_TIDY=ON -DCLANG_TOOLS_PATH="C:/path/to/clang+llvm-18.1.8-x86_64-pc-windows-msvc/bin" ..
cmake --build . --target _run_clang_tidy_project
cmake --build . --target _run_clang_tidy_tests
To use clang-tidy, you need to generate the compile_commands.json file. Run the generate_compile_commands.sh script to generate this file:
./Scripts/generate_compile_commands.sh
Note
If you encounter the following error:
Ninja Does not match the generator used previously.. Either remove the CMakeCache.txt file and CMakeFiles directory or choose a different binary directory.
This error occurs if the build directory specified in the script already exists and was built with a different generator. Either remove the CMake cache or adjust the script to use a different(/new) build directory.