Re: gtk_tree_model_get_iter segfault in on_row_activated
- From: tomas tuxteam de
- To: Christopher Backhouse <cjbackhouse gmail com>
- Cc: gtk-app-devel-list gnome org
- Subject: Re: gtk_tree_model_get_iter segfault in on_row_activated
- Date: Sat, 17 Jun 2006 04:42:16 +0000
On Thu, Jun 15, 2006 at 10:44:57PM +0100, Christopher Backhouse wrote:
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
Ah, but it would be polite of you to provide the place where the
GtkTreeIter lives ;-)
I'll explain myself: at the beginning of the function, you reserve your
space like so:
GkTreeIter iter:
Then you provide a pointer to that in the function call:
if(gtk_tree_model_get_iter(model,&iter,path)==TRUE)
(you might as well g_alloc or g_new your iter, depending on whether you
intend to pass it out of your function. Then you'd have to eventually
free it).
The way you do it now, iter points to some random place in your app's
address space. Thus yes, sometimes it will work, sometimes it'll do
strange things... and most of the time it'll just crash.
HTH
-- tomás
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]