Re: why is class HelloWorld : public Gtk::Window ?
- From: Damon Register <damon w register lmco com>
- To: Murray Cumming <murrayc murrayc com>
- Cc: gtkmm-list gnome org
- Subject: Re: why is class HelloWorld : public Gtk::Window ?
- Date: Mon, 16 Feb 2009 14:12:44 -0500
Murray Cumming wrote:
If you use the derived window system, you should get only one window.
The class instance will use the one that you get from Glade.
I am embarrassed to say that I didn't even think of that. I am
already familiar with the derived idea since I have already learned
to make my own derived widgets (Gtk::DrawingArea so far). This
solution should have been obvious. I modified my hello example
to put this in main()
xml_interface = Gtk::Builder::create_from_file("hello.xml");
xml_interface->get_widget_derived("hello_main_window", window);
I modified the hello constructor like this
hello::hello(BaseObjectType* cobject, const Glib::RefPtr<Gtk::Builder>& refGlade)
: Gtk::Window(cobject) //Calls the base class constructor
{
Now the hello program has only one window and the program actually runs.
I did find that there still is a problem with the Gtk::FileChooserButton
on closing the hello program. It seems that the Gtk::FileChooserButton
just doesn't cleanup well. If I put remove() in the hello destructor
in order to remove the layout widget from the hello window during hello
destruction, I don't get the message
(hello.exe:2684): GLib-GObject-CRITICAL **: g_object_unref: assertion `G_IS_OBJECT (object)' failed
But maybe there's a bug. If so, please do file a bug report with a test
case.
I would be glad to do so but before I do, I need to ask if one is
expected to use the remove() in the hello class or should the window
cleanup gracefully without having to use remove() ?
Does it look like I am finally on the right track with my hello world
example?
Damon Register
SOURCES = hello.cpp
OBJS = ${SOURCES:.cpp=.o}
CPPFLAGS =-g -fomit-frame-pointer `pkg-config gtkmm-2.4 libglademm-2.4 --cflags`
LDADD =`pkg-config gtkmm-2.4 libglademm-2.4 --libs`
CC = g++
PACKAGE = hello.exe
all : ${OBJS}
${CC} -o ${PACKAGE} ${OBJS} ${LDADD}
.cpp.o:
${CC} ${CPPFLAGS} -c $<
#include <iomanip>
#include <sstream>
#include <iostream>
#include <locale.h>
#include <sigc++/retype_return.h>
#include <gtkmm.h>
class hello : public Gtk::Window
{
public:
hello(BaseObjectType* cobject, const Glib::RefPtr<Gtk::Builder>& refGlade);
virtual ~hello();
protected:
virtual bool quitmethod();
Gtk::Button* idc_quit;
Gtk::FileChooserButton* filechooserbutton1;
Gtk::Label* label1;
};
using namespace std;
hello::hello(BaseObjectType* cobject, const Glib::RefPtr<Gtk::Builder>& refGlade)
: Gtk::Window(cobject) //Calls the base class constructor
{
int k;
//Gtk::Layout *layout1;
std::cout << "hello()" << std::endl;
set_title("gtk-builder demo");
set_resizable(false);
//refGlade->get_widget("layout1", layout1);
refGlade->get_widget("label1", label1);
Gtk::Main::signal_quit().connect(sigc::mem_fun(*this, &hello::quitmethod));
refGlade->get_widget("idc_quit", idc_quit);
refGlade->get_widget("filechooserbutton1", filechooserbutton1);
label1->modify_fg(label1->get_state(), Gdk::Color::Color("red"));
label1->modify_base(label1->get_state(), Gdk::Color::Color("black"));
// Set up signal handers for buttons.
idc_quit->signal_clicked().connect( sigc::mem_fun(*this, &hello::hide) );
}
hello::~hello()
{
cout << "~hello()" << endl;
remove();
cout << "~hello() end" << endl;
}
bool hello::quitmethod()
{
std::cout << "quitmethod()" << std::endl;
//remove();
return false;
}
int main(int argc, char *argv[])
{
Gtk::Main kit(argc, argv);
Glib::RefPtr<Gtk::Builder> xml_interface;
hello* window;
Gtk::Window* hello_main_window;
xml_interface = Gtk::Builder::create_from_file("hello.xml");
xml_interface->get_widget_derived("hello_main_window", window);
kit.run(*window);
delete window;
cout << "main() end" << endl;
return 0;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]