[英]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.我是 GTK 和 Rust 的新手,也是 Rust 语言本身的新手,我正在整理一个小型演示应用程序作为练习,有一次我创建了一个content
小部件,我相信它是一个Box
class。
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:我将小部件附加到我的框中,然后附加到我在框小部件中传递的构建器的子属性,换句话说, content
如下:
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:但是使用上面的代码,我在append()
上收到错误消息:
GTK: the method append exists for struct gtk::Box, but its trait bounds were not satisfied. GTK:结构 gtk::Box 存在方法 append,但不满足其特征边界。 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...不满足以下特征界限: gtk::Box: gtk::Box 所需的 IsA: gtk::prelude::UnixFDListExtManual gtk::Box IsA gtk::Box 所需的...
And it just goes on like this.它就这样继续下去。
The error is due to you using the gtk4
method append
on Box
while having gtk
(the gtk3 bindings) in your dependencies.该错误是由于您在Box
上使用gtk4
方法append
而在您的依赖项中具有gtk
(gtk3 绑定)。 If you have gtk4 available on your system you can drop in replace your gtk
dependency to:如果您的系统上有可用的 gtk4,您可以将gtk
依赖替换为:
gtk = { version = "0.5.5", package = "gtk4" }
in your Cargo.toml
在你的Cargo.toml
If you're limited to gtk3 you have to use the gtk3 api of Box
.如果您仅限于 gtk3,则必须使用Box
的 gtk3 api 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.