RE: gtk_widget_destroy



Hi ,
   Can any body help me to find out why i am getting 
segmentation fault for the following code.
What i was indented to do is, as soon as windowa is lauched to the screen,if the lauch is successful then windowB should come and vice versa.
Actually in my last post there was a small error.

/* **************************************************** *
 * File Name	:	windowa.c			*
 * ****************************************************	*/

#include <stdio.h>
#include <gtk/gtk.h>
#include <gdk/gdk.h>
#include <sys/time.h>
#include <string.h>

gint create_winb (GtkWidget *, gpointer);
gint count = 0;
extern GtkWidget *windowb;
GtkWidget *windowa;
gpointer data1;

/* This is a simple call back fuction for closing the window */

void
callback1 (GtkWidget * widget, gpointer data)
{
  g_print ("Pressed key is: %s\n", (gchar *) data);
  gtk_main_quit ();
}

void
callback_event (GtkWidget * widget, gpointer data)
{


  GTimer *evt_tmr = g_timer_new ();
  GtkWidget *image;
  GtkWidget *boxa;
  GtkWidget *buttona;
  GtkWidget *framea;

  widget = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_window_set_title (GTK_WINDOW (widget), "Window Event");
  g_signal_connect (G_OBJECT (widget), "destroy",
		    G_CALLBACK (callback1), (gpointer) "Close");
  gtk_container_set_border_width (GTK_CONTAINER (widget), 20);

  framea = gtk_frame_new (NULL);
  gtk_container_add (GTK_CONTAINER (widget), framea);
  gtk_frame_set_label (GTK_FRAME (framea), "____ Event Window____\n");
  gtk_frame_set_label_align (GTK_FRAME (framea), 1.0, 0.0);

  boxa = gtk_hbox_new (FALSE, 0);
  gtk_container_add (GTK_CONTAINER (framea), boxa);

  image = gtk_image_new_from_file ((gchar *) data);
  gtk_box_pack_start (GTK_BOX (boxa), image, TRUE, TRUE, 0);

  buttona = gtk_button_new_with_label ("Toggle");
  g_signal_connect (G_OBJECT (buttona), "clicked",
		    G_CALLBACK (callback_event), data1);
  gtk_box_pack_start (GTK_BOX (boxa), buttona, TRUE, TRUE, 0);

  printf ("Event Handling time :  %gsec\n", g_timer_elapsed (evt_tmr, NULL));

  gtk_widget_show_all (widget);
  printf ("Event run time :  %gsec\n", g_timer_elapsed (evt_tmr, NULL));
}

gint
create_wina (GtkWidget * widget, gpointer data)
{

  GtkWidget *image;
  GtkWidget *boxa;
  GtkWidget *buttona;
  GtkWidget *framea;
  widget = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_window_set_title (GTK_WINDOW (widget), "Window A");
  g_signal_connect (G_OBJECT (widget), "destroy",
		    G_CALLBACK (create_winb), (gpointer) "Close");


  gtk_container_set_border_width (GTK_CONTAINER (widget), 20);

  framea = gtk_frame_new (NULL);
  gtk_container_add (GTK_CONTAINER (widget), framea);
  gtk_frame_set_label (GTK_FRAME (framea), "____Hello world____\n");
  gtk_frame_set_label_align (GTK_FRAME (framea), 1.0, 0.0);

  boxa = gtk_hbox_new (FALSE, 0);
  gtk_container_add (GTK_CONTAINER (framea), boxa);

  image = gtk_image_new_from_file ((gchar *) data);
  gtk_box_pack_start (GTK_BOX (boxa), image, TRUE, TRUE, 0);

  buttona = gtk_button_new_with_label ("Toggle_A");
  g_signal_connect (G_OBJECT (buttona), "clicked",
		    G_CALLBACK (callback_event), data1);
  gtk_box_pack_start (GTK_BOX (boxa), buttona, TRUE, TRUE, 0);

  gtk_widget_show_all (widget);
  g_print ("toggling to window b\n");
  return 0;
}

int
main (int argc, char *argv[])
{
  GTimer *startup_timer = g_timer_new ();

  data1 = (gpointer) argv[1];

  gtk_init (&argc, &argv);

  if (count == 10)

    {
      g_print ("\nFrames change 10 times...closing appli.....\n");
      gtk_main_quit ();
    }
  else
    {
      create_wina (windowa, data1);
      count++;
    }
  if (GTK_WIDGET_STATE (windowa) == GTK_STATE_NORMAL)
    {
      printf ("Normal\n");
      gtk_widget_destroy (windowa);
    }
  else
    printf ("something\n");
  printf ("startup :  %gsec\n", g_timer_elapsed (startup_timer, NULL));

  gtk_main ();

  printf ("Running Time : %g sec\n", g_timer_elapsed (startup_timer, NULL));


  return 0;
}
/* **************************************************** *
 * File Name	:	windowb.c			*
 * ****************************************************	*/

#include <stdio.h>
#include <gtk/gtk.h>
#include <gdk/gdk.h>

/* This is a simple call back fuction for closing the window */
void callback1 (GtkWidget *, gpointer);
gint create_wina (GtkWidget *, gpointer);
void callback_event (GtkWidget *, gpointer);
extern GtkWidget *windowa;
extern gint count;
GtkWidget *windowb;
extern gpointer data1;
gint
create_winb (GtkWidget * widget, gpointer data)
{

  GtkWidget *image;
  GtkWidget *boxb;
  GtkWidget *buttonb;
  GtkWidget *frameb;

  widget = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_window_set_title (GTK_WINDOW (widget), "Window B");
  g_signal_connect (G_OBJECT (widget), "destroy",
		    G_CALLBACK (create_wina), (gpointer) "Close");
  if (count == 10)
    {
      g_print ("\nFrames change 10 times...closing appli.....\n");
      gtk_main_quit ();
    }
  else
    {
      count++;
      gtk_container_set_border_width (GTK_CONTAINER (widget), 20);

      frameb = gtk_frame_new (NULL);
      gtk_container_add (GTK_CONTAINER (widget), frameb);
      gtk_frame_set_label (GTK_FRAME (frameb), "____Hello World____\n");
      gtk_frame_set_label_align (GTK_FRAME (frameb), 1.0, 0.0);

      boxb = gtk_hbox_new (FALSE, 0);
      gtk_container_add (GTK_CONTAINER (frameb), boxb);

      image = gtk_image_new_from_file ((gchar *) data);
      gtk_box_pack_start (GTK_BOX (boxb), image, TRUE, TRUE, 0);

      buttonb = gtk_button_new_with_label ("Toggle_B");
      g_signal_connect (G_OBJECT (buttonb), "clicked",
			G_CALLBACK (callback_event), data);
      gtk_box_pack_start (GTK_BOX (boxb), buttonb, TRUE, TRUE, 0);

      gtk_widget_show_all (widget);
      g_print ("toggling to window b\n");
  return 0;
}
  return 0;
}



With regds,
Shyjumon N
Mobile: +91-9945006965





<<winmail.dat>>

The information contained in this e-mail message and in any annexure is confidential to the  recipient and may contain privileged information. If you are not the intended recipient, please notify the sender and delete the message along with any annexure. You should not disclose, copy or otherwise use the information contained
in the message or any annexure. Any views expressed in this e-mail are those of the individual sender except where the sender specifically states them to be the views of SoCrates Software India Pvt Ltd., Bangalore.


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