gtk gtkmm示例1 c++

gtkmm入门

使用Gtk.Builder引入glade的UI文件

#include <gtkmm.h>
#include <iostream>

#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<Gtk::Builder> builder;
	try
	{
		builder = Gtk::Builder::create_from_file(UI_FILE);
	}
	catch (const Glib::FileError & ex)
	{
		std::cerr << ex.what() << std::endl;
		return 1;
	}
	Gtk::Window* main_win = 0;
	builder->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

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值