Isurwars/Correlation / .agents/skills/slint-backend
slint-backend
VerifiedDirect modern C++23 integration with Slint GUI, CMake target linkage, thread-safe event loop dispatching, VectorModel data models, and controller architecture. Use when connecting C++ backend logic to Slint UI.
Slint C++ Backend Integration
This skill governs all modern C++23 integrations with the Slint UI framework: CMake build targets, controller architecture, thread-safe event loop synchronization, dynamic data models, and plot/image rendering.
1. CMake Target Integration
Build .slint markup into native C++23 targets via slint_target_sources():
find_package(Slint REQUIRED)
add_executable(correlation src/main.cpp)
slint_target_sources(correlation ui/AppWindow.slint)
target_link_libraries(correlation PRIVATE Slint::Slint correlation_lib)
target_compile_features(correlation PRIVATE cxx_std_23)
2. Controller Architecture & Initialization
C++ applications should instantiate generated Slint windows inside dedicated Controller/ViewModel classes (AppController, PlotController, FileIOHandler) located in src/app/viewmodel/:
#include "AppWindow.h" // Generated by slint_target_sources in CMake
#include <slint/slint.h>
#include <memory>
class AppController {
public:
explicit AppController(slint::ComponentHandle<AppWindow> window)
: window_(std::move(window)) {
bind_callbacks();
}
private:
void bind_callbacks() {
window_->on_run_analysis([this] {
handle_run_analysis();
});
}
void handle_run_analysis();
slint::ComponentHandle<AppWindow> window_;
};
3. Thread-Safe UI Updates (slint::invoke_from_event_loop)
Core Rule
Background threads computing pair distribution functions, reading trajectories, or executing OpenMP loops must never mutate Slint properties directly.
Pattern
Use slint::invoke_from_event_loop() to dispatch back to the GUI event loop, managing async worker lifetimes via RAII std::jthread:
void AppController::handle_run_analysis_async() {
worker_thread_ = std::jthread([window = window_](std::stop_token stop_token) {
auto result = run_pdf_calculation(); // Heavy compute off main thread
if (stop_token.stop_requested()) {
return;
}
slint::invoke_from_event_loop([window, res = std::move(result)] {
window->set_progress(1.0f);
window->set_analysis_status_text(slint::SharedString(res.summary));
});
});
}
4. Type Mapping & Data Models
String Handling
Pass strings using slint::SharedString to prevent memory copies.
Dynamic Collections (slint::VectorModel)
Use slint::VectorModel<T> wrapped in std::shared_ptr for dynamic lists, combo boxes, or tabular datasets:
void populate_preset_list(AppWindow* window, const std::vector<std::string>& presets) {
auto model = std::make_shared<slint::VectorModel<slint::SharedString>>();
for (const auto& preset : presets) {
model->push_back(slint::SharedString(preset));
}
window->set_preset_names(model);
}
RAII Handlers & Callbacks
Bind Slint callbacks to C++ lambdas or member functions using weak references or RAII object lifetimes to avoid dangling memory traps.
5. Plot & Image Buffer Rendering
SVG Buffer → Slint Image
void update_plot_svg(AppWindow* window, const std::string& svg_data) {
auto image = slint::Image::load_from_svg_data(
slint::SharedString(svg_data)
);
window->set_preview_plot(image);
}
Pixel Buffer Rendering
void update_plot_pixels(AppWindow* window, std::span<const uint8_t> rgb_data, uint32_t width, uint32_t height) {
auto pixel_buffer = slint::SharedPixelBuffer<slint::Rgb8Pixel>(width, height);
auto dest_bytes = std::as_writable_bytes(pixel_buffer.as_slice());
std::memcpy(dest_bytes.data(), rgb_data.data(), std::min(dest_bytes.size(), rgb_data.size()));
window->set_preview_plot(slint::Image::from_rgb8(pixel_buffer));
}
6. Unit Testing Controllers
Validate controller state mutations without opening physical display windows:
#include <gtest/gtest.h>
#include "AppWindow.h"
TEST(AppControllerTest, SynchronizesPresetOptions) {
auto window = AppWindow::create();
AppController controller(window);
// Verify initial state and property synchronization
EXPECT_EQ(window->get_file_loaded(), false);
EXPECT_EQ(window->get_progress(), 0.0f);
}
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| brainstormingobra/superpowersYou MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or planning anything new, in software or out of it (a talk, a business, a renovation). | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| brand-guidelinesanthropics/skillsApplies Anthropic's official brand colors and typography to any sort of artifact that may benefit from having Anthropic's look-and-feel. Use it when brand colors or style guidelines, visual formatting, or company design standards apply. | Stars: 197k | Updated | Claude CodeCodex | Verified | Install |
| frontend-designanthropics/skillsGuidance for distinctive, intentional visual design when building new UI or reshaping an existing one. Helps with aesthetic direction, typography, and making choices that don't read as templated defaults. | Stars: 197k | Updated | Claude CodeCodex | Verified | Install |
| mcp-builderanthropics/skillsGuide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when building MCP servers to integrate external APIs or services, whether in Python (FastMCP) or Node/TypeScript (MCP SDK). | Stars: 197k | Updated | Claude CodeCodex | Verified | Install |