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

相关推荐
铅笔侠_小龙虾19 小时前
Rust 学习(4)-函数与注释
开发语言·学习·rust
前端H21 小时前
Biome & Rolldown:Rust 工具链接管前端基建
开发语言·前端·rust
独孤留白1 天前
从C到Rust:struct Cell / RefCell 线程内局部可变性
rust
Kapaseker1 天前
Rust 是如何处理异常的
rust·kotlin
铅笔侠_小龙虾1 天前
Rust 学习(8)-切片类型
学习·rust·c#
程序员爱钓鱼1 天前
Rust 函数与返回值详解:参数、表达式与返回类型
后端·rust
花褪残红青杏小1 天前
Rust图像处理第17节-Julia 朱利亚分形:拖动常数 c 看图实时变化
rust·webassembly·图形学
An_s2 天前
rust开发wasm与浏览器(js)交互
javascript·rust·wasm
Mr -老鬼2 天前
Zed WASM扩展开发全套踩坑记录(WASI适配、LSP插件开发避坑指南)
rust·wasm·lsp·zed·ai ide·语言服务器
糯米导航2 天前
Rust + ONNX Runtime 构建生产级 AI 推理服务:从零到压测
开发语言·人工智能·rust