[glade--] Connecting a signal



I'm a beginner at C++ and I'm trying to use libglademm. I've come up
with the following little program which correctly displays the window
and a few labels I've put into it. However, when I close the window
the program keeps running (in gtk_main, I'm sure). I believe that what
I have to do is connect the glade 'delete_event' for the window to a
handler in my program which calls gtk_main_quit() (eg my
'on_window1_delete_event').

What I can't find out how to do, is actually make the connection! In
the libglademm documentation is the Gnome::Glade::Xml Class Reference,
but while this contains a connect_clicked function, it doesn't have a
more generic function to connect signals.

Can anyone please point the way out of my impasse? I've looked at the
mailing lists back to December 2007 without luck.

Cheers,

Cliff

#include <iostream>
#include <gtkmm.h>
#include <libglademm/xml.h>

using namespace std ;
using namespace Glib ;
using namespace Gnome ;
using namespace Glade ;

bool on_window1_delete_event (GdkEventAny* event) {

    gtk_main_quit() ;
	return true ;

}

int main (int argc,char *argv[] ) {

    Gtk::Window * pWin ;

	// Comment
	cout << "Hello World" << endl ;
    gtk_init(&argc, &argv) ;

    Glib::RefPtr<Gnome::Glade::Xml> refXml;

    try {
	    refXml = Gnome::Glade::Xml::create("hello.glade");
    }
    catch (const Gnome::Glade::XmlError& ex) {
    std::cerr << "Xml create error : " << ex.what() << std::endl;
    return 1;
    }

    // win = refXml->Glade::Xml::get_widget("window1" ) ;
    refXml->get_widget("window1", pWin ) ;
	
	if ( pWin == 0 )
	{
		cout << "get_widget returned zero " << endl ;
	}
	
	// pWin->delete_event.connect(sigc::ptr_fun(on_window1_delete_event) );

	gtk_main() ;
	
	return 0 ;
	
}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]