Skip to content

Getting started

This tutorial shows you how to use the languages that Slint supports as the host programming language.

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

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

Prerequisites

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

  1. Download and extract the ZIP archive of the C++ Template.
  2. Rename the extracted directory and change into it:
Terminal window
mv slint-cpp-template-main memory
cd memory
bash

Configure the project

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

Replace the content of src/main.cpp with the following:

main_initial.cpp
#include "app-window.h" // generated header from ui/app-window.slint
int main(int argc, char **argv)
{
auto main_window = MainWindow::create();
main_window->run();
}
C++

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

Replace the contents of ui/app-window.slint with the following:

app-window.slint
export component MainWindow inherits Window {
Text {
text: "hello world";
color: green;
}
}
slint

Configure with CMake:

Terminal window
cmake -B build
bash

Build with CMake:

Terminal window
cmake --build build
bash

Run the application

Run the application binary on Linux or macOS:

Terminal window
./build/my_application
bash

Or on Windows:

Terminal window
build\my_application.exe
bash

This opens a window with a green “Hello World” greeting.

If you are stepping through this tutorial on a Windows machine, you can run the application at each step with:

Terminal window
my_application
bash

Screenshot of initial tutorial app showing Hello World


© 2024 SixtyFPS GmbH