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

相关推荐
Source.Liu4 小时前
【time-rs】DifferentVariant 错误类型详解(error/different_variant.rs)
rust·time
Source.Liu6 小时前
【time-rs】Format 错误枚举详解(error/format.rs)
rust·time
五仁火烧7 小时前
安装rust开发环境
开发语言·后端·rust
RustCoder9 小时前
Rust 1.92.0 发布:为 Never 类型铺路,强化调试与安全性
程序员·rust·编程语言
古城小栈10 小时前
Go 与 Rust:系统编程语言的竞争与融合
开发语言·golang·rust
柒儿吖10 小时前
深度实战:Rust交叉编译适配OpenHarmony PC——terminal_size完整适配案例
后端·rust·harmonyos
江公望11 小时前
为什么Rust的编译工具依赖C语言的编译工具?
开发语言·rust
Chen--Xing11 小时前
LeetCode 11.盛最多水的容器
c++·python·算法·leetcode·rust·双指针
fegggye12 小时前
创建一个rust写的python库
开发语言·后端·rust
受之以蒙1 天前
Rust 与 dora-rs:吃透核心概念,手把手打造跨语言的机器人实时数据流应用
人工智能·笔记·rust