3

gtk4::Box在使用 gtk-rs 的以下代码中,我不断收到“hbox.pack_start”的错误“由于不满足特征边界而无法调用方法”。我已经在其他 gtk-rs 应用程序和文档中看到了这种方法,所以我不确定我做错了什么。

use gtk::prelude::*;
use gtk::{Application, ApplicationWindow, Button, Label};

fn main() {
    let app = Application::builder()
    .application_id("org.kresslein.rkcounter")
    .build();

    app.connect_activate(build_ui);

    app.run();
}

fn build_ui(app: &Application) {
    let hbox: gtk::Box = gtk::Box::new(gtk::Orientation::Horizontal, 10);
    hbox.set_homogeneous(false);

    let app_title = Label::new(Some("Counter"));
    // Problematic line:
    hbox.pack_start(&app_title, true, true, 0);

    let window = ApplicationWindow::builder()
        .application(app)
        .title("Counter")
        .child(&hbox)
        .build();

    // Present window
    window.present();
}

这是完整的错误消息:

error[E0599]: the method `pack_start` exists for struct `gtk4::Box`, but its trait bounds were not satisfied
  --> src/main.rs:47:10
   |
47 |       hbox.pack_start(&app_title);
   |            ^^^^^^^^^^ method cannot be called on `gtk4::Box` due to unsatisfied trait bounds
   |
  ::: /home/ricky/.cargo/registry/src/github.com-1ecc6299db9ec823/gtk4-0.3.1/src/auto/box_.rs:27:1
   |
27 | / glib::wrapper! {
28 | |     #[doc(alias = "GtkBox")]
29 | |     pub struct Box(Object<ffi::GtkBox, ffi::GtkBoxClass>) @extends Widget, @implements Accessible, Buildable, ConstraintTarget, Orientable;
30 | |
...  |
33 | |     }
34 | | }
   | | -
   | | |
   | |_doesn't satisfy `gtk4::Box: IsA<CellLayout>`
   |   doesn't satisfy `gtk4::Box: gtk4::prelude::CellLayoutExt`
   |
   = note: the following trait bounds were not satisfied:
           `gtk4::Box: IsA<CellLayout>`
           which is required by `gtk4::Box: gtk4::prelude::CellLayoutExt`

For more information about this error, try `rustc --explain E0599`.
4

0 回答 0