treeview---->cursor-changed--->destroy---->seg fault
- From: P V Mathew <pvmathew softhome net>
- To: gtk-app-devel-list gnome org
- Subject: treeview---->cursor-changed--->destroy---->seg fault
- Date: Mon, 13 Sep 2004 20:37:39 +0530
Hello,
I had earlier sent a mail on the following lines:
>I have a gtk2 program which uses gtk tree view.
>I have written a handler for the cursor changed signal.
>The handler calls gtk_widget_destroy on the parent container
>widget.
>I am getting segmentation fault, if I move the
>cursor using the mouse. If I move the cursor using the
>key board all seems fine.
>Would some one help me on why this occurs, and how
>to solve it?
The line which says "If I move the cursor using the mouse
has caused confusion, I think. I am sorry. What I meant was,
if I click on any row in the displayed view, segmentation
fault occurs. If I click on any row I think a cursor-changed
signal gets automatically emitted. But why the seg fault?
The sample code, which was taken from a tutorial, and modified
to demonstrate the point, is once again enclosed, after removing
those useless comments.
****************** beginning of code ******************
/*
* Compile with:
* gcc -o helloworld helloworld.c `pkg-config --cflags --libs gtk+-2.0`
*
*/
#include <gtk/gtk.h>
#include <stdio.h>
enum
{
COL_NAME = 0,
COL_AGE,
NUM_COLS
} ;
struct allv
{
GtkWidget *win;
GtkWidget *view;
} av;
static GtkTreeModel *
create_and_fill_model (void)
{
GtkListStore *store;
GtkTreeIter iter;
store = gtk_list_store_new (NUM_COLS, G_TYPE_STRING, G_TYPE_UINT);
/* Append a row and fill in some data */
gtk_list_store_append (store, &iter);
gtk_list_store_set (store, &iter,
COL_NAME, "Heinz El-Mann",
COL_AGE, 51,
-1);
/* append another row and fill in some data */
gtk_list_store_append (store, &iter);
gtk_list_store_set (store, &iter,
COL_NAME, "Jane Doe",
COL_AGE, 23,
-1);
/* ... and a third row */
gtk_list_store_append (store, &iter);
gtk_list_store_set (store, &iter,
COL_NAME, "Joe Bungop",
COL_AGE, 91,
-1);
return GTK_TREE_MODEL (store);
}
static GtkWidget *
create_view_and_model (void)
{
GtkTreeViewColumn *col;
GtkCellRenderer *renderer;
GtkTreeModel *model;
GtkWidget *view;
view = gtk_tree_view_new ();
/* --- Column #1 --- */
renderer = gtk_cell_renderer_text_new ();
gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (view),
-1,
"Name",
renderer,
"text", COL_NAME,
NULL);
/* --- Column #2 --- */
renderer = gtk_cell_renderer_text_new ();
gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (view),
-1,
"Age",
renderer,
"text", COL_AGE,
NULL);
model = create_and_fill_model ();
gtk_tree_view_set_model (GTK_TREE_VIEW (view), model);
g_object_unref (model); /* destroy model automatically with view */
return view;
}
void my_signal(GtkTreeView *t,gpointer g);
int MainWindow()
{
GtkWidget *window;
GtkWidget *view;
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
g_signal_connect (window, "delete_event", gtk_main_quit, NULL);
av.win = window;
view = create_view_and_model ();
av.view = view;
g_signal_connect(view, "cursor-changed",
(GCallback)my_signal,(gpointer)&av);
gtk_container_add (GTK_CONTAINER (window), view);
gtk_widget_show_all (window);
}
void my_signal(GtkTreeView *t,gpointer g)
{
static int n=1;
if (n != 1)
{
fprintf(stderr,"%s\n","signal received");
n = 1;
gtk_widget_destroy(((struct allv*)g)->win);
//MainWindow();
}
else
n++;
}
int
main (int argc, char **argv)
{
gtk_init (&argc, &argv);
MainWindow();
gtk_main ();
return 0;
}
*************************************end of code *************
Last time I had sent the sample code as attachment.
It did not appear along with the copy of the
message I received. May be the list strips attachments.
so excuse me for sending again.
Does this mean that one cannot destroy the widget
in a CallBack function? Or Is this a Gtk bug?
I am using debian testing linux. with libgtk2 version 2.4.9-1.
p v mathew
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]