Re: While does it segfaults
- From: "Paolo Costabel" <pcostabel futurecombat net>
- To: "Fabio Rotondo" <mlists rotondo it>
- Cc: "gtk-devel" <gtk-app-devel-list gnome org>
- Subject: Re: While does it segfaults
- Date: Mon, 17 Dec 2001 09:16:52 -0800
You can't memcpy gtk objects. They contain pointers and stuff.
To duplicate a GtkAdjustment, you need to allocate a new one.
In your case, you don't need a new adjustment object. Change your code as
follows:
void show ( GtkWidget * w )
{
GtkAdjustment * adj
adj = gtk_scrolled_window_get_vadjustment ( GTK_SCROLLED_WINDOW
scrolledwindow1 ) );
printf ( "Value: %f\n", adj->value );
gtk_adjustment_set_value(adj,39.0);
}
----------------------------------------------------------------
Paolo Costabel
Sony Imageworks
----- Original Message -----
From: "Fabio Rotondo" <mlists rotondo it>
To: "gtk-devel" <gtk-app-devel-list gnome org>
Sent: Monday, December 17, 2001 8:14 AM
Subject: While does it segfaults
Hi list,
could anyone please tell me why this piece of code segfaults?
Do the following:
1 - Run the app
2 - Move the vscrollbar (in the middle)
3 - Press the button
4 - Try to move the vscrollbar again -> segfault
Thanks,
Fabio
----------------------------------------------------------------------------
----
/*
* DO NOT EDIT THIS FILE - it is generated by Glade.
*/
#include <string.h>
#include <gtk/gtk.h>
GtkWidget *clist1;
GtkWidget *scrolledwindow1;
void show ( GtkWidget * w )
{
GtkAdjustment * adj;
GtkAdjustment a;
adj = gtk_scrolled_window_get_vadjustment ( GTK_SCROLLED_WINDOW
scrolledwindow1 ) );
memcpy ( &a, adj, sizeof ( GtkAdjustment ) );
printf ( "Value: %f\n", a.value );
a.value = 39.0;
gtk_scrolled_window_set_vadjustment ( GTK_SCROLLED_WINDOW
scrolledwindow1 ), &a );
}
int main ( int argc, char * argv[] )
{
GtkWidget *window1;
GtkWidget *vbox1;
GtkWidget *label3;
GtkWidget *label4;
GtkWidget *label5;
GtkWidget *button1;
int t;
char * a[4];
gtk_init ( &argc, &argv );
window1 = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_object_set_data (GTK_OBJECT (window1), "window1", window1);
vbox1 = gtk_vbox_new (FALSE, 0);
gtk_container_add (GTK_CONTAINER (window1), vbox1);
scrolledwindow1 = gtk_scrolled_window_new (NULL, NULL);
gtk_widget_show (scrolledwindow1);
gtk_box_pack_start (GTK_BOX (vbox1), scrolledwindow1, TRUE, TRUE, 0);
clist1 = gtk_clist_new (3);
gtk_container_add (GTK_CONTAINER (scrolledwindow1), clist1);
gtk_clist_set_column_width (GTK_CLIST (clist1), 0, 80);
gtk_clist_set_column_width (GTK_CLIST (clist1), 1, 80);
gtk_clist_set_column_width (GTK_CLIST (clist1), 2, 80);
gtk_clist_column_titles_show (GTK_CLIST (clist1));
label3 = gtk_label_new ("label3");
gtk_clist_set_column_widget (GTK_CLIST (clist1), 0, label3);
label4 = gtk_label_new ("label4");
gtk_clist_set_column_widget (GTK_CLIST (clist1), 1, label4);
label5 = gtk_label_new ("label5");
gtk_clist_set_column_widget (GTK_CLIST (clist1), 2, label5);
button1 = gtk_button_new_with_label ("button1");
gtk_box_pack_start (GTK_BOX (vbox1), button1, FALSE, FALSE, 0);
gtk_signal_connect ( GTK_OBJECT ( button1 ), "clicked", show, NULL );
a[0] = "one";
a[1] = "two";
a[2] = "three";
for ( t = 0; t < 40; t++)
gtk_clist_append ( GTK_CLIST ( clist1 ), a );
gtk_widget_show_all ( window1 );
gtk_main ();
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]