在我的 Rust GTK 应用程序中,我有这个,但是,我认为它也适用于 C++:
let builder = Builder::new_from_file("main_window.glade");
当我在 Release模式或什至在 Debug模式下编译我的应用程序时,我想摆脱使用文件“main_window.glade”分发可执行文件的必要性。
如何将 glade 文件静态链接或嵌入到可执行文件中?
最佳答案
Rust 标准库提供了 include_str!
宏,它允许您将文件的内容作为静态字符串 (&'static str
) 包含到您的程序中,然后您可以将其分配给一个全局常量。
const MAIN_WINDOW: &'static str = include_str!("main_window.glade");
然后,您可以使用 Builder::new_from_string
使用该字符串构建 UI:
let builder = Builder::new_from_string(MAIN_WINDOW);
如果你只想使用常量一次,那么你可以直接使用include_str!
:
let builder = Builder::new_from_string(include_str!("main_window.glade"));
关于gtk - GTK 中的 new_from_file()——我总是需要那个 "glade"文件吗?我可以嵌入它吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36963495/