Rust GTK Hello World 示例
Rust GTK Hello World Example
我正在尝试使用 gtk 和 Rust this hello world 应用程序
use gtk::prelude::*;
use gtk::{Application, ApplicationWindow};
fn main() {
let app = Application::builder()
.application_id("org.example.HelloWorld")
.build();
app.connect_activate(|app| {
// We create the main window.
let win = ApplicationWindow::builder()
.application(app)
.default_width(320)
.default_height(200)
.title("Hello, World!")
.build();
// Don't forget to make all widgets visible.
win.show_all();
});
app.run();
}
我在编译示例时遇到一些问题,我得到的编译错误是
error[E0599]: no function or associated item named `builder` found for struct `Application` in the current scope
--> src/main.rs:5:28
|
5 | let app = Application::builder()
| ^^^^^^^ function or associated item not found in `Application`
error[E0599]: no function or associated item named `builder` found for struct `ApplicationWindow` in the current scope
--> src/main.rs:11:38
|
11 | let win = ApplicationWindow::builder()
| ^^^^^^^ function or associated item not found in `ApplicationWindow`
这是我的 Cargo.toml 文件 -
[package]
name = "color-picker"
version = "0.1.0"
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
chrono = "0.4"
futures = "0.3"
atk = "^0"
glib-sys = "^0"
gobject-sys = "^0"
glib = "^0"
gio = "^0"
gdk = "^0"
gdk-pixbuf = "^0"
gtk = "^0"
once_cell = "^0"
pango = "^0"
pangocairo = "^0"
cascade = "^0"
cairo-rs = { version = "^0", features = ["png"] }
[features]
#default = ["gtk_3_22_30"]
gtk_3_18 = ["gtk/v3_18", "gdk-pixbuf/v2_32", "gdk/v3_18", "gio/v2_46", "glib/v2_46", "pango/v1_38"] #for CI tools
gtk_3_22_30 = ["gtk_3_18", "gtk/v3_22_30", "gdk-pixbuf/v2_36", "gdk/v3_22", "gio/v2_56", "glib/v2_56", "pango/v1_42"] #for CI tools
gtk_3_24 = ["gtk_3_22_30", "gtk/v3_24", "atk/v2_30", "gdk-pixbuf/v2_36_8", "gdk/v3_24", "gio/v2_58", "glib/v2_58"] #for CI tools
我是否遗漏了一些东西来编译它?
谢谢!
编辑:修复了 Cargo.toml 文件
您的Cargo.toml
修改后仍然不正确。
它很可能应该看起来像这样:
[package]
name = "color-picker"
version = "0.1.0"
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
gtk = "0.14.0"
引用来自 crates.io 的 gtk
箱子。
我正在尝试使用 gtk 和 Rust this hello world 应用程序
use gtk::prelude::*;
use gtk::{Application, ApplicationWindow};
fn main() {
let app = Application::builder()
.application_id("org.example.HelloWorld")
.build();
app.connect_activate(|app| {
// We create the main window.
let win = ApplicationWindow::builder()
.application(app)
.default_width(320)
.default_height(200)
.title("Hello, World!")
.build();
// Don't forget to make all widgets visible.
win.show_all();
});
app.run();
}
我在编译示例时遇到一些问题,我得到的编译错误是
error[E0599]: no function or associated item named `builder` found for struct `Application` in the current scope
--> src/main.rs:5:28
|
5 | let app = Application::builder()
| ^^^^^^^ function or associated item not found in `Application`
error[E0599]: no function or associated item named `builder` found for struct `ApplicationWindow` in the current scope
--> src/main.rs:11:38
|
11 | let win = ApplicationWindow::builder()
| ^^^^^^^ function or associated item not found in `ApplicationWindow`
这是我的 Cargo.toml 文件 -
[package]
name = "color-picker"
version = "0.1.0"
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
chrono = "0.4"
futures = "0.3"
atk = "^0"
glib-sys = "^0"
gobject-sys = "^0"
glib = "^0"
gio = "^0"
gdk = "^0"
gdk-pixbuf = "^0"
gtk = "^0"
once_cell = "^0"
pango = "^0"
pangocairo = "^0"
cascade = "^0"
cairo-rs = { version = "^0", features = ["png"] }
[features]
#default = ["gtk_3_22_30"]
gtk_3_18 = ["gtk/v3_18", "gdk-pixbuf/v2_32", "gdk/v3_18", "gio/v2_46", "glib/v2_46", "pango/v1_38"] #for CI tools
gtk_3_22_30 = ["gtk_3_18", "gtk/v3_22_30", "gdk-pixbuf/v2_36", "gdk/v3_22", "gio/v2_56", "glib/v2_56", "pango/v1_42"] #for CI tools
gtk_3_24 = ["gtk_3_22_30", "gtk/v3_24", "atk/v2_30", "gdk-pixbuf/v2_36_8", "gdk/v3_24", "gio/v2_58", "glib/v2_58"] #for CI tools
我是否遗漏了一些东西来编译它?
谢谢!
编辑:修复了 Cargo.toml 文件
您的Cargo.toml
修改后仍然不正确。
它很可能应该看起来像这样:
[package]
name = "color-picker"
version = "0.1.0"
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
gtk = "0.14.0"
引用来自 crates.io 的 gtk
箱子。