Re: ScrolledWindow::remove() problem



Of course, here's a little app that crashes under Windows but seems to run OK 
in Linux. You'll need to click the button twice, since the ScrolledWindow is 
empty the first time. #define EXAMPLE_STANDARD_WIDGETS if you want to use 
standard widgets instead of the derived class, in which case the app should run 
without problems even under Windows.
These are the tested configurations:
Linux (GCC-4.1.1):
- Build: Gtk-2.8.19/Gtkmm-2.8.3 - Runtime: Gtk-2.8.19/Gtkmm-2.8.3 -> OK!
Windows (XP, Mingw32-GCC-4.1.1 and Mingw32-GCC-3.4.6):
- Build: Gtk/Gtkmm-2.6 - Runtime: Gtk/Gtkmm-2.8 -> Crashes with derived widget.
- Build: Gtk/Gtkmm-2.8 - Runtime: Gtk/Gtkmm-2.8 -> Crashes with derived widget.

I should mention the Windows libraries (build + runtime) are the binaries 
provided by Cedric Gustin.
-------------------------------------------------------------------------------

#include <gtkmm/window.h>
#include <gtkmm/scrolledwindow.h>
#include <gtkmm/layout.h>
#include <gtkmm/button.h>
#include <gtkmm/main.h>
#include <gtkmm/box.h>
#include <gtkmm/tooltips.h>
#include <gtkmm/label.h>

/* Define me to use standard widgets. */
/* Undefine me to use the derived class below. */
//#define EXAMPLE_STANDARD_WIDGETS

/* This is the evil class! */
class c_DerivedLayout : public Gtk::Layout
{
public:
   //We do nothing.
   c_DerivedLayout()
   {
      /* Comment me out, if you think I'm guilty =) */
      put(*Gtk::manage(new Gtk::Label("Hello")), 5, 5);
      show_all_children();
      /* ------------------------------------------ */
   }
};

class c_Window : public Gtk::Window
{
public:
   c_Window()
   {
      set_default_size(400, 400);
      add(m_vboxBox);
      m_vboxBox.pack_start(m_scrollwScroll);
      m_vboxBox.pack_end(m_butButton);
      m_butButton.set_label("Click Me Twice! =)");
      l_auxTip.set_tip(m_butButton, "Whenever you click me, I'll remove the 
contained "
                                    "widget from the ScrolledWindow above me, 
and then "
                                    "add a new widget. The first time you do 
so, there'll "
                                    "be no contained widget, so everything 
should work as expected. "
                                    "Click me again, and, if we are in Windows, 
I'll die.");
      m_butButton.signal_clicked().connect(sigc::mem_fun(*this, 
&c_Window::on_m_butButton_clicked));
      
      show_all_children();
   }
   
private:   
   void on_m_butButton_clicked()
   {
      /* If there is no widget inside the ScrolledWindow,
         or, if the contained widget is a standard widget,
         everything works as expected.*/
      m_scrollwScroll.remove();
      /* We work with unmanaged widgets, so in this case
         we have a leak (this is obviously avoided in the
         original project).*/
#ifdef EXAMPLE_STANDARD_WIDGETS
      m_scrollwScroll.add(*new Gtk::Layout);
#else
      m_scrollwScroll.add(*new c_DerivedLayout);
#endif
   }
   
   Gtk::Tooltips l_auxTip;
   Gtk::VBox m_vboxBox;
   Gtk::ScrolledWindow m_scrollwScroll;
   Gtk::Button m_butButton;
};

int main(int argc, char** argv)
{
   Gtk::Main l_Main(argc, argv);
   c_Window l_Window;
   l_Main.run(l_Window);
   return 0;
}





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