slint/docs/tutorial/cpp/src/getting_started.md
Chris Chinchilla 9345638191
Refactor CPP Quickstart to use project template project (#4722)
* Refactor CPP Quickstart to use project template project

* Update docs/tutorial/cpp/src/main_initial.cpp

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* Update docs/tutorial/cpp/src/game_logic_in_cpp.md

Co-authored-by: Simon Hausmann <simon.hausmann@slint.dev>

* Update docs/tutorial/cpp/src/creating_the_tiles_from_cpp.md

Co-authored-by: Simon Hausmann <simon.hausmann@slint.dev>

* Update docs/tutorial/cpp/src/from_one_to_multiple_tiles.md

Co-authored-by: Simon Hausmann <simon.hausmann@slint.dev>

* Update docs/tutorial/cpp/src/from_one_to_multiple_tiles.md

Co-authored-by: Simon Hausmann <simon.hausmann@slint.dev>

* Update docs/tutorial/cpp/src/getting_started.md

Co-authored-by: Simon Hausmann <simon.hausmann@slint.dev>

* Remove commented text

* Re-add removed powershell icon commands

* Undo rename

* Correct path in CMakeLists.txt

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Simon Hausmann <simon.hausmann@slint.dev>
2024-03-11 15:09:01 +01:00

1.9 KiB

Getting Started

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

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:

{{#include main_initial.cpp:main}}

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:

{{#include appwindow.slint:main_window}}

Configure with CMake:

cmake -B build

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

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.