使用rust slint开发桌面应用

安装QT5,过程省略

安装rust,过程省略

创建工程

cargo new slint_demo

在cargo.toml添加依赖

dependencies

slint = "1.1.1"

build-dependencies

slint-build = "1.1.1"

创建build.rs

rust 复制代码
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

TypeScript 复制代码
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

rust 复制代码
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%

相关推荐
程序员爱钓鱼3 小时前
Rust 所有权 Ownership 详解:理解内存安全的核心机制
前端·后端·rust
k4m7v2pz13 小时前
把 Bevy 0.14 游戏移植到 R36S 掌机:一场与“无窗口系统“的搏斗
linux·rust·bevy·r36s·rk3326·开源掌机
doiito14 小时前
【Agent Harness】流马(Gliding Horse)DeepSeek Responses API 接入介绍
rust·系统设计·ai agent
SomeB1oody20 小时前
【RustyML入门】2.0. 经典机器学习
开发语言·后端·机器学习·rust·教程
Embedded-Xin21 小时前
Rust学习——Cargo工具
linux·学习·架构·rust·嵌入式
龙仔72521 小时前
RustDesk 完整笔记
运维·笔记·rust·远程工具·rustdesk
An_s1 天前
rust(pdfium)底层开发实现wasm包给vue3调用
开发语言·rust·wasm
对象存储与RustFS1 天前
为什么越来越多的企业选择RustFS作为对象存储?
后端·rust·开源
KryptonWright2 天前
让 AI Agent 只能提议、不能擅自执行:Rust 中 prepare-confirm-execute 权限模型的实现
rust
起司喵喵2 天前
推荐一款基于 Python 和 Rust 开发的跨平台 GUI 自动化库!
python·rust·自动化