libglademm, menus



Hello,

I have a problem instantiating menus from glade files. 
Two versions of a simple program are attached below - one crashes (seg
faults) when accessing the File menu, while the other one works.

I have also attached the glade file below.

-karthik

--------------works.cpp-----------
#include <gtkmm/statusbar.h>
#include <gtkmm/window.h>
#include <gtkmm/frame.h>
#include <gtkmm/main.h>
#include <gtkmm/messagedialog.h>
#include <libglademm/xml.h>

#include <iostream>
#include <sigc++/retype_return.h>

class test : public Gtk::Window {
public:
  test(Glib::RefPtr<Gnome::Glade::Xml> refXml) {
    //Glib::RefPtr<Gnome::Glade::Xml> refXml=
Gnome::Glade::Xml::create("input.glade","main_vbox");
    Gtk::VBox *main_vbox;
    refXml->get_widget("main_vbox",main_vbox);
    add(*main_vbox);
    set_default_size(300,300);
    set_size_request(200,200);
    
    Gtk::Statusbar *status;
    refXml->get_widget("StatusBar",status);
    status->push("Created plot");
  };
  virtual ~test() { };
};

int main(int argc, char **argv) {
  Gtk::Main  main_instance(argc,argv);

  //Gtk::Window *window = new test();//refXml);//new Gtk::Window();
  Glib::RefPtr<Gnome::Glade::Xml> refXml=
Gnome::Glade::Xml::create("input.glade","main_vbox");

  if(refXml==NULL)
    return 0;
  Gtk::Window *window = new test(refXml);//new Gtk::Window();

  main_instance.run(*window);

  return 0;
}


-------------buggy.cpp----------------------
#include <gtkmm/statusbar.h>
#include <gtkmm/window.h>
#include <gtkmm/frame.h>
#include <gtkmm/main.h>
#include <gtkmm/messagedialog.h>
#include <libglademm/xml.h>

#include <iostream>
#include <sigc++/retype_return.h>

class test : public Gtk::Window {
public:
  test(){//Glib::RefPtr<Gnome::Glade::Xml> refXml) {
    Glib::RefPtr<Gnome::Glade::Xml> refXml=
Gnome::Glade::Xml::create("input.glade","main_vbox");
    Gtk::VBox *main_vbox;
    refXml->get_widget("main_vbox",main_vbox);
    add(*main_vbox);
    set_default_size(300,300);
    set_size_request(200,200);
    
    Gtk::Statusbar *status;
    refXml->get_widget("StatusBar",status);
    status->push("Created plot");
  };
  virtual ~test() { };
};

int main(int argc, char **argv) {
  Gtk::Main  main_instance(argc,argv);

  Gtk::Window *window = new test();//refXml);//new Gtk::Window();
#if 0
  Glib::RefPtr<Gnome::Glade::Xml> refXml=
Gnome::Glade::Xml::create("input.glade","main_vbox");

  if(refXml==NULL)
    return 0;
  Gtk::Window *window = new test(refXml);//new Gtk::Window();
#endif
  main_instance.run(*window);

  return 0;
}

--------------------------input.glade------------------------
<?xml version="1.0" standalone="no"?> <!--*- mode: xml -*-->
<!DOCTYPE glade-interface SYSTEM "http://glade.gnome.org/glade-2.0.dtd";>

<glade-interface>

<widget class="GtkWindow" id="StripChartTest">
  <property agent="glademm" name="cxx_visibility">public</property>
  <property name="visible">True</property>
  <property name="title" translatable="yes">window1</property>
  <property name="type">GTK_WINDOW_TOPLEVEL</property>
  <property name="window_position">GTK_WIN_POS_NONE</property>
  <property name="modal">False</property>
  <property name="resizable">True</property>
  <property name="destroy_with_parent">False</property>
  <property name="decorated">True</property>
  <property name="skip_taskbar_hint">False</property>
  <property name="skip_pager_hint">False</property>
  <property name="type_hint">GDK_WINDOW_TYPE_HINT_NORMAL</property>
  <property name="gravity">GDK_GRAVITY_NORTH_WEST</property>
  <property name="focus_on_map">True</property>
  <property name="urgency_hint">False</property>

  <child>
    <widget class="GtkVBox" id="main_vbox">
      <property agent="glademm" name="cxx_visibility">public</property>
      <property name="visible">True</property>
      <property name="homogeneous">False</property>
      <property name="spacing">0</property>

      <child>
	<widget class="GtkMenuBar" id="menubar1">
	  <property agent="glademm" name="cxx_visibility">public</property>
	  <property name="visible">True</property>
	  <property name="pack_direction">GTK_PACK_DIRECTION_LTR</property>
	  <property
name="child_pack_direction">GTK_PACK_DIRECTION_LTR</property>

	  <child>
	    <widget class="GtkMenuItem" id="menuitem1">
	      <property name="visible">True</property>
	      <property name="label" translatable="yes">_File</property>
	      <property name="use_underline">True</property>

	      <child>
		<widget class="GtkMenu" id="menuitem1_menu">

		  <child>
		    <widget class="GtkImageMenuItem" id="new1">
		      <property name="visible">True</property>
		      <property name="label">gtk-new</property>
		      <property name="use_stock">True</property>
		    </widget>
		  </child>

		  <child>
		    <widget class="GtkSeparatorMenuItem" id="separatormenuitem1">
		      <property name="visible">True</property>
		    </widget>
		  </child>

		  <child>
		    <widget class="GtkImageMenuItem" id="quit1">
		      <property name="visible">True</property>
		      <property name="label">gtk-quit</property>
		      <property name="use_stock">True</property>
		    </widget>
		  </child>
		</widget>
	      </child>
	    </widget>
	  </child>

	  <child>
	    <widget class="GtkMenuItem" id="menuitem4">
	      <property name="visible">True</property>
	      <property name="label" translatable="yes">_Help</property>
	      <property name="use_underline">True</property>

	      <child>
		<widget class="GtkMenu" id="menuitem4_menu">

		  <child>
		    <widget class="GtkImageMenuItem" id="about1">
		      <property name="visible">True</property>
		      <property name="label">gtk-about</property>
		      <property name="use_stock">True</property>
		    </widget>
		  </child>
		</widget>
	      </child>
	    </widget>
	  </child>
	</widget>
	<packing>
	  <property name="padding">0</property>
	  <property name="expand">False</property>
	  <property name="fill">False</property>
	</packing>
      </child>

      <child>
	<widget class="GtkFrame" id="StripChartHolder">
	  <property agent="glademm" name="cxx_visibility">public</property>
	  <property name="visible">True</property>
	  <property name="label_xalign">0</property>
	  <property name="label_yalign">0.5</property>
	  <property name="shadow_type">GTK_SHADOW_NONE</property>

	  <child>
	    <placeholder/>
	  </child>

	  <child>
	    <placeholder/>
	  </child>
	</widget>
	<packing>
	  <property name="padding">0</property>
	  <property name="expand">True</property>
	  <property name="fill">True</property>
	</packing>
      </child>

      <child>
	<widget class="GtkStatusbar" id="StatusBar">
	  <property name="visible">True</property>
	  <property name="has_resize_grip">True</property>
	</widget>
	<packing>
	  <property name="padding">0</property>
	  <property name="expand">False</property>
	  <property name="fill">False</property>
	</packing>
      </child>
    </widget>
  </child>
</widget>

</glade-interface>





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