Hello World!
This is the smallest useful QTML application: a Rust entry point, one template, and a Cargo manifest. render_qtml! compiles the page markup while render_qtml_styles! generates the default theme and the template's native CSS. The Rust entry point places both results into a complete HTML document.
my-qtml-app/
|-- Cargo.toml
|-- src/
| `-- main.rs
`-- ui/
`-- page.qtml
Cargo.toml
[package]
name = "my-qtml-app"
version = "0.1.0"
edition = "2024"
[dependencies]
qtml_macro = "0.1"
src/main.rs
use qtml_macro::{render_qtml, render_qtml_styles};
const PAGE_STYLES: &str = render_qtml_styles!("ui/page.qtml");
fn main() {
let content = render_qtml!("ui/page.qtml");
println!(
r#"<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Hello QTML</title>
<style>{PAGE_STYLES}</style>
</head>
<body>
{content}
</body>
</html>"#
);
}
ui/page.qtml
Page {
Column {
horizontal_alignment: center
vertical_alignment: center
min_height: 100vh
spacing: 1rem
Header1 { text: "Hello, world!" }
Text { text: "Rendered with Rust, QTML, and generated CSS." }
}
}
Run cargo run > index.html, then open index.html in a browser. QTML compiles the markup and stylesheet during the Rust build. Passing the same ui/page.qtml entrypoint to both macros keeps the generated classes and CSS rules in sync.