Skip to content

Instantly share code, notes, and snippets.

@khws4v1
Last active August 29, 2015 14:23
Show Gist options
  • Select an option

  • Save khws4v1/48799f839b01aaaf9391 to your computer and use it in GitHub Desktop.

Select an option

Save khws4v1/48799f839b01aaaf9391 to your computer and use it in GitHub Desktop.
gtkmm-3.0の練習
cmake_minimum_required(VERSION 3.0)
project(test_glade CXX)
find_package(PkgConfig)
pkg_check_modules(Gtkmm gtkmm-3.0)
pkg_check_modules(Glibmm glibmm-2.4)
include_directories(${Gtkmm_INCLUDE_DIRS}
${Glibmm_INCLUDE_DIRS})
add_executable(test_glade main.cpp)
target_link_libraries(test_glade
${Gtkmm_LIBRARIES}
${Glibmm_LIBRARIES})
#include <gtkmm.h>
Gtk::Label* label;
static void on_button1_clicked()
{
if (label)
label->set_text("Hello World!");
}
int main(int argc, char **argv)
{
Glib::RefPtr<Gtk::Application> a = Gtk::Application::create(argc, argv, "test");
Gtk::Window* window;
Glib::RefPtr<Gtk::Builder> builder = Gtk::Builder::create();
builder->add_from_file("test.glade");
builder->get_widget("window1", window);
if (window) {
Gtk::Button* button;
builder->get_widget("button1", button);
builder->get_widget("label1", label);
if (button)
button->signal_clicked().connect(sigc::ptr_fun(on_button1_clicked));
window->resize(400, 250);
a->run(*window);
}
delete window;
return 0;
}
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.18.3 -->
<interface>
<requires lib="gtk+" version="3.0"/>
<object class="GtkWindow" id="window1">
<property name="can_focus">False</property>
<child>
<object class="GtkBox" id="box1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkLabel" id="label1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">label</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="button1">
<property name="label" translatable="yes">クリック!</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<signal name="clicked" handler="on_button1_clicked" object="label1" swapped="yes"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
</child>
</object>
</interface>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment