[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]
Re: seg fault while moving a event box
- From: abhi <abhi_don_linux yahoo com>
- To: abhi <abhi_don_linux yahoo com>, gtk-app-devel-list gnome org
- Subject: Re: seg fault while moving a event box
- Date: Mon, 14 Jan 2008 17:24:47 -0800 (PST)
Sorry folks,
the declaration of the move callback has to be
static void move( GtkWidget *widget,
GdkEventButton *event,
GtkWidget *layout )
I was missing the event parameter and that probably
caused the casting errors.
Thanks for reading,
Regards,
Abhijeet
--- abhi <abhi_don_linux yahoo com> wrote:
> Hello List,
>
> This is my first GTK app and I want to move the
> image when the user clicks on it. I created an
> eventbox and placed it on a GtkLayout. I catch the
> mouse_pressed event but when I move the event_bx I
> get
> a segfault. I dont have the symbols from the
> libraries
> but gdb tells me this
>
>
> Breakpoint 1, move (widget=0x94a10e8,
> layout=0x94aef68) at g2.c:14
> 14 g_print("button_press_event_received\n");
> (gdb) step
> button_press_event_received
> 15 x = (x + 30) % 300;
> (gdb) step
> 16 y = (y + 50) % 300;
> (gdb) step
> 18 gtk_layout_get_size ( GTK_LAYOUT (layout)
> ,
> &width, &height);
> (gdb) print width
> $1 = -1073765136
> (gdb) print height
> $2 = 155848184
> (gdb) step
>
> Program received signal SIGSEGV, Segmentation fault.
> 0x0017015c in g_type_check_instance_cast () from
> /usr/lib/libgobject-2.0.so.0
> (gdb) Quit
>
>
> The source code is as follows
> #include <gtk/gtk.h>
> #include <stdlib.h>
> gint x = 50;
> gint y = 50;
> GtkWidget *image = NULL;
> /* This callback function moves the button to a new
> position
> * in the layout container. */
> static void move( GtkWidget *widget,
> GtkWidget *layout )
> {
> gint width,height;
> g_print("button_press_event_received\n");
> x = (x + 30) % 300;
> y = (y + 50) % 300;
> gtk_layout_get_size ( GTK_LAYOUT (layout) ,
> &width,
> &height);
> gtk_layout_move ( GTK_LAYOUT(layout), widget , x,
> y);
> }
> void usage()
> {
> g_print(" incorrect usage need a image
> parameter\n");
> exit( EXIT_FAILURE );
> }
> int main( int argc,
> char *argv[] )
> {
> /* GtkWidget is the storage type for widgets */
> GtkWidget *window;
> GtkWidget *layout;
> GtkWidget *event_box;
> GtkWidget *button;
> GdkPixbuf *pixbuf;
> gint i;
>
> if (argc < 2) usage();
>
> /* Initialise GTK */
> gtk_init (&argc, &argv);
>
> /* Create a new window */
> window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
> gtk_window_set_title (GTK_WINDOW (window), "Layout
> Container");
>
> /* Here we connect the "destroy" event to a signal
> handler */
> g_signal_connect (G_OBJECT (window), "destroy",
> G_CALLBACK (gtk_main_quit), NULL);
>
> /* Sets the border width of the window. */
> gtk_container_set_border_width (GTK_CONTAINER
> (window), 10);
>
> /* Create a Layout Container */
> layout = gtk_layout_new ( NULL, NULL);
> gtk_container_add (GTK_CONTAINER (window),
> layout);
> gtk_widget_show (layout);
>
> /* Create an image widget form the pixbuf */
> pixbuf = gdk_pixbuf_new_from_file(argv[1],NULL);
> image = gtk_image_new_from_pixbuf (pixbuf);
>
> /* Create an event box and add image widget*/
> event_box = gtk_event_box_new ();
> gtk_container_add (GTK_CONTAINER (event_box),
> image);
> gtk_widget_show (image);
>
> /*put the event box somewhere on the layout */
> gtk_layout_put (GTK_LAYOUT (layout), event_box, 50
> ,
> 50 );
> gtk_widget_show (event_box);
>
> /* And bind an action to it */
> gtk_widget_set_events (event_box,
> GDK_BUTTON_PRESS_MASK);
> g_signal_connect (G_OBJECT (event_box),
> "button_press_event",
> G_CALLBACK (move), layout);
> gtk_widget_realize (event_box);
>
> /* Display the window */
> gtk_widget_show (window);
>
> /* Enter the event loop */
> gtk_main ();
>
> return 0;
> }
> /*
> gcc g2.c -o g2 `pkg-config --cflags --libs gtk+-2.0`
> */
>
>
> Any help educating me towards the cause of segfault
> will be appreciated.
>
> TIA,
> Abhijeet
>
>
>
>
____________________________________________________________________________________
> Be a better friend, newshound, and
> know-it-all with Yahoo! Mobile. Try it now.
>
http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ
>
>
> _______________________________________________
> gtk-app-devel-list mailing list
> gtk-app-devel-list gnome org
>
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
>
____________________________________________________________________________________
Be a better friend, newshound, and
know-it-all with Yahoo! Mobile. Try it now. http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ
[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]