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

Re: destroying widgets on C++



Germano Leichsenring wrote:
> 
> I have a class which have a window in it; I want the class to be destroyed
> when the widget is destroyed, and the widget be destroyed when the class is
> destroyed. I've been trying it for a while, but can't find a solution that
> works. Has anybody done that?
> 

Something like this?

void
Gtk_alerta::destruye_objeto_cb(GtkWidget *widget, gpointer una_ventana)
{
  gpointer el_objeto;

  el_objeto = gtk_object_get_user_data (GTK_OBJECT(una_ventana));
  //g_print("El objeto vale: %x\n",el_objeto);
  delete static_cast<Gtk_alerta *>(el_objeto);
}

Gtk_alerta::Gtk_alerta(const string &titulo, const string &un_texto,
                       const string &un_boton)
{

  la_ventana = gtk_window_new (GTK_WINDOW_DIALOG);
  gtk_window_set_title(GTK_WINDOW(la_ventana),titulo.c_str());
  gtk_object_set_user_data(GTK_OBJECT(la_ventana), this);

  ...
  gtk_signal_connect (GTK_OBJECT(el_boton), "clicked",
                      GTK_SIGNAL_FUNC(destruye_objeto_cb), la_ventana);

  ....

}

Hope to help you.

A. Corbi



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