gtk gtkmm示例1 c++

Veronica ·
更新时间:2024-11-13
· 687 次阅读

gtkmm入门 使用Gtk.Builder引入glade的UI文件 #include #include #include "config.h" /* For testing propose use the local (not installed) ui file */ /* #define UI_FILE PACKAGE_DATA_DIR"/ui/gtk_foobar.ui" */ #define UI_FILE "src/gtk_foobar.ui" void button1_clicked_cb() { std::cout << "hello" << std::endl; } int main (int argc, char *argv[]) { Gtk::Main kit(argc, argv); //Load the Glade file and instiate its widgets: Glib::RefPtr builder; try { builder = Gtk::Builder::create_from_file(UI_FILE); } catch (const Glib::FileError & ex) { std::cerr << ex.what() <get_widget("main_window", main_win); //创建button1,并指向UI中的Button(ID:button1) Gtk::Button* button1 = 0; builder->get_widget("button1", button1); button1->signal_clicked().connect(sigc::ptr_fun(&button1_clicked_cb)); if (main_win) { kit.run(*main_win); } return 0; }

运行图
在这里插入图片描述
参考链接:
https://developer.gnome.org/gtkmm/3.24/
https://developer.gnome.org/glibmm/unstable/classGlib_1_1SignalProxy_3_01void_07T_8_8_8_08_4.html#a27b7862ec4b6f24bdb7fc7382bdd89e0
https://developer.gnome.org/gtkmm-tutorial/stable/sec-connecting-signal-handlers.html.en


作者:greatyoulv



c+ gtk C++

需要 登录 后方可回复, 如果你还没有账号请 注册新账号