Getting Started

This tutorial uses C++ as the host programming language. Slint also supports other programming languages like Rust or JavaScript.

We recommend using our editor integrations for Slint for following this tutorial.

Slint has an application template you can use to create a project with dependencies already set up that follows recommended best practices.

Before using the template, you need a C++ compiler that supports C++ 20 and to install CMake 3.21 or newer.

Clone or download template repository:

git clone https://github.com/slint-ui/slint-cpp-template memory
cd memory

The CMakeLists.txt uses the line add_executable(my_application src/main.cpp) to set src/main.cpp as the main C++ code file.

Change the content of src/main.cpp to the following:

// src/main.cpp

#include "appwindow.h" // generated header from memory.slint

int main(int argc, char **argv)
{
    auto main_window = MainWindow::create();
    main_window->run();
}

Also in CMakeLists.txt the line slint_target_sources(my_application ui/appwindow.slint) is a Slint function used to add the appwindow.slint file to the target.

Change the contents of ui/appwindow.slint to the following:

// ui/appwindow.slint
export component MainWindow inherits Window {
    Text {
        text: "hello world";
        color: green;
    }
}

Configure with CMake:

cmake -B build

Note: When configuring with CMake, the FetchContent module fetches the source code of Slint via git. This may take some time when building for the first time, as the process needs to build the Slint runtime and compiler.

Build with CMake:

cmake --build build

Run the application binary on Linux or macOS:

./build/my_application

Windows:

build\my_application.exe

This opens a window with a green "Hello World" greeting.

If you are stepping through this tutorial on a Windows machine, you can run it with

my_application

Screenshot of initial tutorial app showing Hello World