Re: gtk_tree_model_get_iter segfault in on_row_activated
- From: Christopher Backhouse <cjbackhouse gmail com>
- To: blythe2 tcnj edu
- Cc: gtk-app-devel-list gnome org
- Subject: Re: gtk_tree_model_get_iter segfault in on_row_activated
- Date: Fri, 16 Jun 2006 19:07:40 +0100
You are both right - it now works fine. Thanks for pointing out what was
right under my nose. I do honestly know what I am doing with pointers -
I think this is the effects of code written at 2 in the morning and then
seeing what should have been there upon trying to debug it.
"All the parameters I pass are at least existing" should have been a
hint as to where the trouble lay....
Now I'm embarrassed - I think I will crawl away and hide for a bit (at
least with my faith in GTK restored though)
blythe2 tcnj edu wrote:
Iter needs to be an actual object, not just a pointer. You are *creating*
a n iterator, then passing it by reference to be filled. As your code
stands now, you're passing an uninitialized pointer to be written to,
which of course crashes. Try the following:
void on_row_activated(GtkTreeView* tree_view,GtkTreePath*
path,GtkTreeViewColumn* column,gpointer user_data)
{
std::cout<<"path was "<<gtk_tree_path_to_string(path)<<"\n";
GtkTreeModel* model=gtk_tree_view_get_model(tree_view);
if(model!=NULL)
std::cout<<"got the model OK\n";
else
std::cout<<"failed to get the model\n";
std::cout<<"trying to get the iter\n";
GtkTreeIter iter;
if(gtk_tree_model_get_iter(model,&iter,path)==TRUE)
std::cout<<"got the iter ok\n";
else
std::cout<<"didn't get the iter\n";
}
That should work better. Hope that helps!
-Nate
I have connected to the row activated signal and want to handle it - so
I am doing this:
void on_row_activated(GtkTreeView* tree_view,GtkTreePath*
path,GtkTreeViewColumn* column,gpointer user_data)
{
std::cout<<"path was "<<gtk_tree_path_to_string(path)<<"\n";
GtkTreeModel* model=gtk_tree_view_get_model(tree_view);
if(model!=NULL)
std::cout<<"got the model OK\n";
else
std::cout<<"failed to get the model\n";
std::cout<<"trying to get the iter\n";
GtkTreeIter* iter;
if(gtk_tree_model_get_iter(model,iter,path)==TRUE)
std::cout<<"got the iter ok\n";
else
std::cout<<"didn't get the iter\n";
}
upon double-clicking an item in the list output looks something like (in
this case the 4th entry)
path was 3
got the model OK
trying to get the iter
Segmentation fault
although bizarrely it very occasionally works fine.
Any ideas? It's a bit impolite to segfault when all the parameters I
pass are at least existing
_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]