1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
|
#include <gtkmm/box.h>
#include <gtkmm/button.h>
#include <gtkmm/label.h>
#include <gtkmm/window.h>
#include <gtkmm/main.h>
class AppWindow
: public Gtk::Window
{
public:
AppWindow();
private:
void on_button_clicked();
Gtk::Label* m_label;
};
AppWindow::AppWindow()
: m_label (0)
{
Gtk::Box* vbox = Gtk::manage(new Gtk::VBox (false, 5));
add(*vbox);
Gtk::Button* button = Gtk::manage(new Gtk::Button("Delete Label"));
vbox->pack_start(*button, Gtk::PACK_SHRINK);
//m_label = manage (new Gtk::Label ("test"));
m_label = new Gtk::Label("test");
g_warning("m_label -> ref_count: %d\n", G_OBJECT(m_label->gobj())->ref_count);
vbox->pack_start(*m_label, Gtk::PACK_SHRINK);
g_warning("m_label -> ref_count: %d\n", G_OBJECT(m_label->gobj())->ref_count);
button->signal_clicked().connect( sigc::mem_fun(*this, &AppWindow::on_button_clicked));
show_all_children();
}
void AppWindow::on_button_clicked()
{
if(m_label)
{
g_warning("AppWindow::on_button_clicked(): label refcount=%d", G_OBJECT(m_label->gobj())->ref_count);
delete m_label;
m_label = 0;
}
}
int main(int argc, char *argv[])
{
Gtk::Main kit(&argc, &argv);
AppWindow app;
Gtk::Main::run(app);
return(0);
}
|