The following sections explain how to integrate your
.slint designs into your
C++ application. The entry point is the
.slint file containing the primary
component you need to instantiate from C++.
Slint is a very flexible system and allows for different integration options.
First you can compile your Slint designs ahead of time into C++ code. This code is then built into your application. This allows for the smallest possible memory footprint and the best possible performance.
The second approach is to load your Slint designs at run-time, interpreting them as needed. This enables even more dynamic user interfaces that can be changed at run-time, but comes at the price of having less opportunity to apply optimizations.
Either way, once your user interface is shown, you interact with it from C++, for example by setting properties, populating data models or setting up and handling callbacks to react to events triggered by the user.
The provided CMake integration makes it easy to compile your Slint sources:
slint_target_sources CMake command makes the translation automatic. The
generated code has an API to set and get property values,
etc. This API uses types from the slint namespace, for
Instead of compiling
.slint designs to C++, you can dynamically load
files at run-time. This is slower than compiling them ahead of time and requires
more memory, however it provides more flexibility in your application design.
The entry point to loading a
.slint file is the
slint::interpreter::ComponentCompiler class in the
With the help of
slint::interpreter::ComponentCompiler you create
slint::interpreter::ComponentDefinition, which provides
information on properties and callbacks common to all instances. The
slint::interpreter::ComponentDefinition::create() function creates
new instances, wrapped in a
slint::ComponentHandle. This is a smart
pointer that owns the actual instance and keeps it alive as long as at least one
slint::ComponentHandle is in scope, similar to
All property values in
.slint are mapped to
slint::interpreter::Value in C++. This is a polymorphic data type
that can hold different kinds of values, such as numbers, strings or even data
More complex user interfaces commonly consume data in the form of an abstract
data model, that is used with
ListView elements in the
.slint language. All models in C++ with the interpreter API are sub-classes
slint::Model where the template parameter is
slint::interpreter::Value. To provide your own data model, you can
It’s possible to declare singletons that are globally available
.slint files. You can access them from to your C++ code by exporting them
and using the getter and setter functions on
slint::interpreter::ComponentInstance to change properties and