gtk-- - delete causes sigsegv



I try this simple application and get a sigsegv when I press the close
button. I saw in your code for the destructor the comment that you hide
the window to prevent the sigsegv from occuring. I must be missing
something
that should be called before deleting the pointer.

How should I go about deleting windows?

thanks
Todd

/*
The following command should make a binary called 'deleteTest'

 g++ -o deleteTest `gtk-config --cflags` `gtk-config --libs` -lgtkmm deleteTest.C

 */

#include <stream.h>
#include <gdk/gdkx.h>
#include <gtk--.h>

static char * pc_rcs_h = "global_h";
static char * pc_rcs = "$Id: comboStrings.C,v 1.1 1998/05/12 16:07:13 tdukes Exp $";

#define USE(var) static void * use_##var = (void *) var
USE( pc_rcs_h);
USE( pc_rcs);

class SecondWindow : public Gtk_Window {
public:
  SecondWindow() : label("second window") { label.show(); add(&label);show();}
  Gtk_Label label;
};

class MyWindow : public Gtk_Window {
public:
  MyWindow();
  Gtk_Button open; /* create a child window */
  Gtk_Button close; /* delete this window */
  Gtk_Button quit;
  Gtk_VBox   vbox;
  void openPushed();
  void closePushed();
  SecondWindow * secondWindow;
};

MyWindow::MyWindow():
  open("open"),
  close("close"),
  quit("quit"),
  secondWindow(0) {
  open.show();
  close.show();
  quit.show();
  vbox.show();
  add(&vbox);
  vbox.pack_start(&open);
  vbox.pack_start(&close);
  vbox.pack_start(&quit);
  connect_to_method( open.clicked, this, &(MyWindow::openPushed));
  connect_to_method( close.clicked, this, &(MyWindow::closePushed));
  connect_to_method( quit.clicked, Gtk_Main::instance(), &Gtk_Main::quit);
}

void MyWindow::openPushed() {
  secondWindow = new SecondWindow;
  secondWindow->show();
}

void MyWindow::closePushed() {
  delete secondWindow;
  secondWindow = 0;
}

int main(int argc, char *argv[]) {
  Gtk_Main m(&argc, &argv);
  XSynchronize( GDK_DISPLAY(), False); /* true makes synchronous,
                                            false is asynchronous */
  MyWindow myWindow;
  myWindow.show();
  m.run();
  return 0;
}


/* ==============================================================
   | Todd Dukes                      E-MAIL:  tdukes@ibmoto.com |
   | Motorola Somerset                  Phone:   (512) 424-8008 |
   | MS OE70                                                    |
   | 6300 Bridgepoint Parkway Building #3                       |
   | Austin, Texas 78730                                        |
   ==============================================================*/





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