安装QT5,过程省略
安装rust,过程省略
创建工程
cargo new slint_demo
在cargo.toml添加依赖
[dependencies]
slint = “1.1.1”
[build-dependencies]
slint-build = “1.1.1”
创建build.rs
fn main() {slint_build::compile("ui/main.slint").unwrap();println!("cargo:rustc-link-lib=static=Qt5Core");println!("cargo:rustc-link-search=native=D:/Qt/qt/5.15.2/msvc2019_64/lib");}
创建UI文件main.slint
import {GroupBox, LineEdit, Button} from "std-widgets.slint";export component MainWindow inherits Window {title: "slint demo";width: 640px;height: 480px;VerticalLayout { alignment:start;padding-left: 25px;padding-right: 25px;Text { font-size: 27px;font-weight: 700;color: #6776FF; }GroupBox{title:"用户名";LineEdit {placeholder-text: "请输入用户名";}}Button {text: "登录";clicked => { self.text = "单击"; }}}}
创建main.rs
slint::include_modules!();fn main() { MainWindow::new().unwrap().run().unwrap();}
目录结构
编译
cargo build
运行
cargo run
把qt的dll文件路径加入PATH环境变量
set PATH=D:\Qt\qt\5.15.2\msvc2019_64\bin;%PATH%