Skip to main content

C++ API

The public headers are the source of truth. The generated pages in Generated API mirror the declarations and comments from the headers in include/shadcn.

Generated signatures can omit default arguments and qualifiers. Open the linked header when the exact declaration matters.

Targets and includes​

The library selects C++26 when the compiler supports it, with C++23 as the minimum. Include shadcn/core.hpp for the value and timing API without Qt. Include shadcn/shadcn.hpp for the widget set. The optional video player uses shadcn/media.hpp and the separate shadcn::media target.

find_package(shadcn 0.1.1 EXACT REQUIRED COMPONENTS core widgets)
target_link_libraries(app PRIVATE shadcn::core shadcn::widgets)
#include <shadcn/shadcn.hpp>

All names are in the shadcn namespace. The version constant is shadcn::version, currently "0.1.1".

Ownership and threads​

Qt owns a widget constructed with a parent. make_child returns a borrowed reference to that widget.

auto& button = shadcn::make_child<shadcn::Button>(window, "Continue");
layout.addWidget(&button);

Do not delete the returned reference or place it in an owning smart pointer. Do not retain it after its parent is destroyed. Use QPointer<T> when an observer may outlive the immediate call. Create and access widgets on the GUI thread.

Application setup​

install installs a Style on the application. A zero or negative font size keeps the current application font size.

QApplication app(argc, argv);
shadcn::install(app, shadcn::Theme::neutral(), shadcn::MotionPolicy::Reduced);

Composing a card​

A card owns its layout hosts. Their accessors return borrowed references, so ordinary Qt composition still works.

auto& card = shadcn::make_child<shadcn::Card>(window);
card.setTitle("Modern C++");
card.setDescription("Continue the current lesson.");
auto& button = shadcn::make_child<shadcn::Button>(card, "Continue");
card.content().addWidget(&button);

Generated pages​

The generated reference is grouped by namespace, class, enum and function. Use the component pages for construction examples and the generated pages for declaration details.

The documentation site keeps the generator local to the project. The public library does not depend on Node or any documentation tool at runtime.