Movatterモバイル変換


[0]ホーム

URL:


ContentsMenuExpandLight modeDark modeAuto light/dark, in light modeAuto light/dark, in dark modeSkip to content
Slint 1.12.1 C++ API documentation
Logo
Slint 1.12.1 C++ API documentation

Getting Started On Desktop

Getting Started on MCU

C++ / .slint Integration

Reference

Third-Party Licenses

Back to top

Set Up Development Environment

Prerequisites

  • A C++ compiler that supports C++20 (e.g.,MSVC 2019 16.6 on Windows)

  • cmake (3.21 or newer)

    • Slint comes with a CMake integration that automates the compilation step of the.slint markup language files and offers a CMake target for convenient linkage.

    • Note: We recommend using the Ninja generator of CMake for the most efficient build and.slint dependency tracking. InstallNinja and select the CMake Ninja backend by passing-GNinja or set theCMAKE_GENERATOR environment variable toNinja.

Install Slint

To install Slint, either download thebinary packages orbuild from sources.

Note: Binary packages are available for only Linux and Windows on x86-64 architecture. The recommended and most flexible way to use the C++ API is to build Slint from sources.

Install Binary Packages

The Slint binary packages work without any Rust development environment.

Steps:

  1. Openhttps://github.com/slint-ui/slint/releases

  2. Click on the latest release

  3. From “Assets” (“XXX” refers to the version of the latest release),

    • for Linux x86-64 architecture - downloadslint-cpp-XXX-Linux-x86_64.tar.gz

    • for Windows x86-64 architecture - downloadslint-cpp-XXX-win64-MSVC.exe

  4. Unpack the downloaded archive (Linux) or run the installer executable (Windows).

  5. Set environment variables

    • setCMAKE_PREFIX_PATH to the installation directory of Slint. Alternatively you can pass-DCMAKE_PREFIX_PATH=/path/to/installed/slint argument when invoking cmake. This helpsfind_package(Slint) to find Slint from within aCMakeLists.txt file.

    • add thelib sub-directory in the installation directory of Slint toLD_LIBRARY_PATH (Linux) or to thePATH environment variable (Windows). This is necessary to find the Slint libraries when running a Slint program.

In the next section you will learn how to use the installed library in your application and how to work with.slint UI files.

Build From Sources

First you need to install the prerequisites:

  • Install Rust by following theRust Getting Started Guide. If you alreadyhave Rust installed, make sure that it’s at least version 1.85 or newer. You can check which version you have installedby runningrustc--version. Once this is done, you should have therustc compiler and thecargo build system installed in your path.

You can either choose to compile Slint from source along with your application or include Slint as an external CMake package.

  • To compile Slint along with your application, include Slint into your CMake project using CMake’sFetchContent feature. Insert the following snippet into yourCMakeLists.txt to make CMake download the latest released 1.x version, compile it, and make the CMakeintegration available:

include(FetchContent)FetchContent_Declare(SlintGIT_REPOSITORYhttps://github.com/slint-ui/slint.git# `release/1` will auto-upgrade to the latest Slint >= 1.0.0 and < 2.0.0# `release/1.0` will auto-upgrade to the latest Slint >= 1.0.0 and < 1.1.0GIT_TAGrelease/1SOURCE_SUBDIRapi/cpp)FetchContent_MakeAvailable(Slint)
  • To include Slint as an external CMake package, build Slint from source like a regular CMake project, install it into a prefix directory of your choice and usefind_package(Slint) in yourCMakeLists.txt.

Features

The Slint library supports a set of features, not all of them enabled by default.You might want to adapt the set of enabled features to optimize your binarysize. For example you might want to support only the wayland stack on Linux.Enable thebackend-winit-wayland feature while turning off thebackend-winit-x11 feature to do so.

Slint’s CMake configuration uses CMake options prefixed withSLINT_FEATURE_ toexpose Slint’s feature flags at compile time. To have a wayland-only stack withthe CMake setup you would for example use:

cmake-DSLINT_FEATURE_BACKEND_WINIT=OFF-DSLINT_FEATURE_BACKEND_WINIT_WAYLAND=ON...

Alternatively, you can usecmake-gui orccmake for a more interactive wayto discover and toggle features.

This works when compiling Slint as a package, usingcmake--build andcmake--install, or when including Slint usingFetchContent.

If you need to check in your application’sCMakeLists.txt whether a feature is enabledor disabled, read theSLINT_ENABLED_FEATURES andSLINT_DISABLED_FEATURES targetproperties from theSlint::Slint cmake target:

get_target_property(slint_enabled_features Slint::Slint SLINT_ENABLED_FEATURES)if ("BACKEND_WINIT" IN_LIST slint_enabled_features)    ...endif()

Similarly, if you need to check for features at compile-time, check for the existenceofSLINT_FEATURE_<NAME> pre-processor macros:

#include <slint.h>#if defined(SLINT_FEATURE_BACKEND_WINIT)//...#endif

Rust Flags

Slint usesCorrosion to build Slint, which is developed in Rust. You can utilizeCorrosion’s global CMake variables to control certain aspects of the Rust build process.

Furthermore, you can set theSLINT_LIBRARY_CARGO_FLAGS cache variable to specify additional flags for the Slint runtime during the build.

Platform Backends

In Slint, a backend is the module that encapsulates the interaction with the operating system,in particular the windowing sub-system. Multiple backends can be compiled into Slint and onebackend is selected for use at run-time on application start-up. You can configure Slint withoutany built-in backends, and instead develop your own backend by implementing Slint’s platformabstraction and window adapter interfaces.

For more information about the available backends, their system requirements, and configurationoptions, see theBackend & Renderers Documentation.

By default Slint will include both the Qt andwinit back-ends – if both are detected atcompile time. You can enable or disable back-ends using theSLINT_FEATURE_BACKEND_ features. For example, to exclude the winit back-end,you would disable theSLINT_FEATURE_BACKEND_WINIT option in your CMakeproject configuration.

The winit back-end needs a renderer.SLINT_FEATURE_RENDERER_FEMTOVG andSLINT_FEATURE_RENDERER_SKIA are the only stable renderers, the other ones areexperimental.

Cross-compiling

It’s possible to cross-compile Slint to a different target architecture whenbuilding with CMake. You need to make sure your CMake setup is ready forcross-compilation, as documented in theupstream CMake documentation.

If you are building against a Yocto SDK, it is sufficient to source the SDK’s environment setup file.

Since Slint is implemented using the Rust programming language, you need todetermine which Rust target matches the target architecture that you’recompiling for. Please consult theupstream Rust documentation to find the correct target name. Now you need to install the Rust toolchain:

rustuptargetadd<target-name>

Then you’re ready to iconfigure your CMake project you need to add-DRust_CARGO_TARGET=<targetname> to the CMake command line.This ensures that the Slint library is built for the correct architecture.

For example if you are building against an embedded Linux Yocto SDK targetingan ARM64 board, the following commands show how to compile:

Install the Rust targe toolchain once:

rustuptargetaddaarch64-unknown-linux-gnu

Set up the environment and build:

./path/to/yocto/sdk/environment-setup-cortexa53-crypto-poky-linuxcd<PROJECT_ROOT>mkdirbuildcdbuildcmake-DRust_CARGO_TARGET=aarch64-unknown-linux-gnu-DCMAKE_INSTALL_PREFIX=/slint/install/path..cmake--build.cmake--install.
On this page

[8]ページ先頭

©2009-2025 Movatter.jp