使用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%

相关推荐
容智信息10 小时前
AI Agent(智能体)的输出格式应该从 Markdown 转向 HTML吗?
前端·人工智能·rust·编辑器·html·prompt
Rust研习社18 小时前
Rust Clippy 实用指南:写出更优雅、安全的 Rust 代码
后端·rust·编程语言
yangyongdehao3018 小时前
两天用AI+rust撸了一款本地批量去水印软件,30MB,效果能打
ai作画·rust
nudt_qxx19 小时前
NVIDIA 正式开源cuda-oxide!Rust 编写 CUDA 内核新范式!
rust
小杍随笔2 天前
【Rust桌面革命:Tauri×Dioxus——架构对决、实战拆解与2026选型杀招】
开发语言·架构·rust
whinc2 天前
Rust技术周刊 2026年第17周
后端·rust
whinc2 天前
Rust技术周刊 2026年第18周
后端·rust
whinc2 天前
Rust技术周刊 2026年第16周
后端·rust
星辰徐哥2 天前
Rust异步测试与调试的实践指南
android·java·rust