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

相关推荐
明月看潮生17 小时前
青少年编程与数学 02-019 Rust 编程基础 08课题、字面量、运算符和表达式
开发语言·青少年编程·rust·编程与数学
天天打码17 小时前
Rspack:字节跳动自研 Web 构建工具-基于 Rust打造高性能前端工具链
开发语言·前端·javascript·rust·开源
姜 萌@cnblogs21 小时前
开源我的一款自用AI阅读器,引流Web前端、Rust、Tauri、AI应用开发
rust·web·tauri·svelte
明月看潮生1 天前
青少年编程与数学 02-019 Rust 编程基础 05课题、复合数据类型
开发语言·青少年编程·rust·编程与数学
Uncomfortableskiy2 天前
Rust 官方文档:人话版翻译指南
开发语言·rust
大卫小东(Sheldon)2 天前
GIM: 调用AI自动生成git提交消息的工具
git·rust
大G哥2 天前
Rust 之 trait 与泛型的奥秘
java·开发语言·jvm·数据结构·rust
Source.Liu2 天前
【typenum】 1 说明文件(README.md)
rust
蜗牛沐雨3 天前
Rust 中的 Pin 和 Unpin:内存安全与异步编程的守护者
服务器·开发语言·rust
hrrrrb3 天前
【Rust】枚举和模式匹配
开发语言·rust