CCWrapper test applet
- From: Mikael Hermansson <mikeh bahnhof se>
- To: gtk-list redhat com
- Subject: CCWrapper test applet
- Date: Wed, 6 Jan 1999 23:36:30 +0100 (CET)
I trying to write an Gtk applet in C++
doing this will not work memory corruption.
when callback calls DestroyObject() it sigsegv
looks like pointer has been overwritten somewhere...
class MainWindow
{
bool bDestroy=false;
GtkWidget *window;
public:
MainWindow(gchar *title);
~MainWindow();
gint DestroyObject();
void MainLoop();
GtkWidget * GetWidget(){ return window;};
};
void cb_destroy(GtkWidget *w,MainWindow *mptr)
{
if(mptr->DestroyObject) /* In this example it should return false */
delete mptr; /*so the object will not destroy in callback
*/
/* main will doit when MainLoop returns */
}
MainWindow::MainWindow(gchar *title)
{
bDestroy=false;
window=gtk_window_new();
gtk_window_title(GTK_WINDOW(window),title);
gtk_signal_connect(GTK_OBJECT(window),"delete_event",GTK_SIGNAL_FUNC(cb_destroy),this);
}
MainWindow::~MainWindow()
{
}
void MainWindow::MainLoop
{
bDestroy=false; /* Make sure object will not destroy in callback*/
gtk_main();
}
gint MainWindow::ObjectDestroy()
{
gtk_main_quit();
return bDestroy;
}
main(int c,char *arg)
{
MainWindow *ptr=NULL;
gtk_init(&c,&arg);
ptr=new MainWindow("Craptest");
ptr->MainLoop();
delete ptr;
}
http://www.bahnhof.se/~mikeh
E-mail: mikeh@bahnhof.se
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]