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

相关推荐
姜 萌@cnblogs3 小时前
Saga Reader 0.9.9 版本亮点:深入解析核心新功能实现
前端·ai·rust
susnm4 小时前
使用路由重构代码
rust·全栈
Pomelo_刘金17 小时前
用 DDD 把「闹钟」需求一点点捏出来
架构·rust·领域驱动设计
Pomelo_刘金18 小时前
Clean Architecture 整洁架构:借一只闹钟讲明白「整洁架构」的来龙去脉
后端·架构·rust
a cool fish(无名)1 天前
rust-方法语法
开发语言·后端·rust
a cool fish(无名)2 天前
rust-参考与借用
java·前端·rust
叶 落2 天前
[Rust 基础课程]猜数字游戏-获取用户输入并打印
rust·rust基础
RustFS2 天前
RustFS 如何修改默认密码?
rust
景天科技苑2 天前
【Rust线程池】如何构建Rust线程池、Rayon线程池用法详细解析
开发语言·后端·rust·线程池·rayon·rust线程池·rayon线程池
该用户已不存在3 天前
Zig想要取代Go和Rust,它有资格吗
前端·后端·rust