Search code examples
rustgtk

GTK: the method append exists for struct gtk::Box, but its trait bounds were not satisfied


I am brand new to GTK with Rust as well as being new to the Rust language itself and I am putting together a small demo app as practice and at one point I created a content widget which is a Box class I believe.

let content = Box::new(Orientation: Vertical, 0);
content.append(&label);
content.append(&button);

I appended the widgets into my box and then on the child property of the builder I passed in the box widget, in other words content like so:

let window = ApplicationWindow::builder()
     .title("UI Demo")
     .application(_app)
     .child(&content)
     .build();

But with the above code, I am getting an error on append() saying:

GTK: the method append exists for struct gtk::Box, but its trait bounds were not satisfied. The following trait bounds were not satisfied: gtk::Box: IsA which is required by gtk::Box: gtk::prelude::UnixFDListExtManual gtk::Box IsA which is required by gtk::Box...

And it just goes on like this.


Solution

  • The error is due to you using the gtk4 method append on Box while having gtk (the gtk3 bindings) in your dependencies. If you have gtk4 available on your system you can drop in replace your gtk dependency to:

    gtk = { version = "0.5.5", package = "gtk4" }
    

    in your Cargo.toml

    If you're limited to gtk3 you have to use the gtk3 api of Box.