使用 gtk-rs

问题描述

这是一个示例项目:

use gtk::prelude::*;
use gtk::{Application,applicationwindow};

fn main() {
    let app = Application::builder()
        .application_id("org.example.HelloWorld")
        .build();
    app.connect_activate(|app| {
        let win = applicationwindow::builder().application(app).build();

        example(&win);

        win.connect_add(move |_,_| {
            example(&win);
        });

        win.show_all();
    });

    app.run();
}

fn example(test: &applicationwindow) {
    test.connect_show_menubar_notify(move |_| {
        example(test);
    });
}

来自 cargo run错误

error[E0621]: explicit lifetime required in the type of `test`
  --> src/main.rs:22:10
   |
21 | fn example(test: &applicationwindow) {
   |                  ------------------ help: add explicit lifetime `'static` to the type of `test`: `&'static applicationwindow`
22 |     test.connect_show_menubar_notify(move |_| {
   |          ^^^^^^^^^^^^^^^^^^^^^^^^^^^ lifetime `'static` required

我使用的依赖项是 gtk = "0.14.0",但我在使用 gtk-rs git 版本时也遇到了这个问题。

问题出在哪里?我是初学者;我必须做哪些改变?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)