Type Mappings#

The types used for properties in .slint design markup each translate to specific types in C++. The follow table summarizes the entire mapping:

.slint Type

C++ Type

Note

int

int

float

float

bool

bool

string

slint::SharedString

A reference-counted string type that uses UTF-8 encoding and can be easily converted to a std::string_view or a const char *.

color

slint::Color

brush

slint::Brush

image

slint::Image

physical_length

float

The unit are physical pixels.

length

float

At run-time, logical lengths are automatically translated to physical pixels using the device pixel ratio.

duration

std::int64_t

At run-time, durations are always represented as signed 64-bit integers with millisecond precision.

angle

float

The value in degrees.

relative-font-size

float

Relative font size factor that is multiplied with the Window.default-font-size and can be converted to a length.

structure

A class of the same name

The order of the data member are in the same as in the slint declaration

Structures#

The Slint compiler generates a class with all data members in lexicographic order for any user-defined, exported struct in the .slint code.

For example, this struct in a .slint file

export struct MyStruct {
    foo: int,
    bar: string,
}

will generate the following type in C++:

class MyStruct {
public:
    int foo;
    slint::SharedString bar;
};