I have following code to find if row is selected, which is selected and which text is in row of GtkTreeView. Code is in key-release event handler.
char *ntext;
if (gtk_tree_selection_get_selected(treeselen, &modelen ,&iteren))
{
gtk_tree_model_get(modelen, &iteren, cEng, &ntext, -1);
... etc...
This works ok when my view is not empty. But when list is empty I get “segmentation fault”.
I think that before this is needed to check if GtkTreeView is empty.
How to do that?
Actually, later I find if list is partially filled with clicking on unfilled area segfault happens too. So I need solution for that too.
From your description, it appears when you say
GtkTreeViewis empty you mean in model (GtkTreeModelwhich is implemented byGtkListStoreorGtkTreeStoreassociated with yourGtkTreeView) the data rows are added but are empty i.e. data is not set. In that case you need to check the value returned bygtk_tree_model_get(assumingcEngis valid otherwise you will get a warning message while running the program). Problem mostly is in...etc.... Just add aNULLcheck tontextbefore operating on it.This could also be the case in you button-press or release callback as well.
Hope this helps!