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

相关推荐
ftzchina12 小时前
Rust学习总结之-枚举
rust·枚举
祈澈菇凉12 小时前
什么是Sass,如何使用?
前端·rust·sass
SomeB1oody1 天前
【Rust中级教程】2.10. API设计原则之受约束性(constrained) Pt.1:对类型进行修改、`#[non_exhaustive]`注解
开发语言·后端·性能优化·rust
Hello.Reader1 天前
Rust 并发编程:使用消息传递进行线程间数据共享
c++·算法·rust
SomeB1oody1 天前
【Rust中级教程】2.9. API设计原则之显然性(obvious) :文档与类型系统、语义化类型、使用“零大小”类型
开发语言·后端·rust
Vitalia2 天前
从入门到精通Rust:资源库整理
开发语言·后端·rust
m0_663234012 天前
Rust并发编程实践:10分钟入门系统级编程
python·算法·rust
放羊郎2 天前
CUDA兼容NVIDA版本关系
开发语言·后端·rust
zdsji2 天前
如何制作安装包打包软件
算法·rust·vue
Hello.Reader2 天前
Rust 中的引用循环与内存泄漏
开发语言·windows·rust