Re: gtk_selection_get_selected()
- From: Owen Taylor <otaylor redhat com>
- To: Jens Hornung <dncn gmx net>
- Cc: "gtk-app-devel-list gnome org" <gtk-app-devel-list gnome org>
- Subject: Re: gtk_selection_get_selected()
- Date: 08 Apr 2003 11:18:25 -0400
On Tue, 2003-04-08 at 10:30, Jens Hornung wrote:
Hi,
i've got some problems with the function 'gtk_selection_get_selected'. Here's a part of the code:
...
GtkListStore *list;
GtkTreeView *view;
GtkTreeSelection *selection;
GtkTreeIter iter;
GValue *value;
...
selection = gtk_tree_view_get_selection(view);
gtk_tree_selection_set_mode(selection, GTK_SELECTION_SINGLE);
if((gtk_tree_selection_get_selected(GTK_TREE_SELECTION(selection),
GTK_TREE_MODEL(&list),
&iter))
== TRUE)
{
gtk_tree_model_get_value(GTK_TREE_MODEL(list),
&iter,
1,
value);
g_printf("%s\n", (gchar *)value);
g_value_unset(value);
}
...
gcc always stops with the message:
ad.c: In function `main':
ad.c:360: warning: passing arg 2 of `gtk_tree_selection_get_selected' from incompatible pointer type
Can someone give me a hint, how to do that right.
Well, hmmm, the way I'd write the above is:
GtkTreeModel *model;
GtkTreeView *view;
GtkTreeSelection *selection;
GtkTreeIter iter;
...
selection = gtk_tree_view_get_selection(view);
gtk_tree_selection_set_mode(selection, GTK_SELECTION_SINGLE);
if (gtk_tree_selection_get_selected(selection, &model, &iter))
{
char *str;
gtk_tree_model_get_value(model, &iter,
1, &str,
-1);
g_print ("%s\n", str);
g_free (str);
}
Explaining all the differences in detail would take a while, but
to answer your immediate question -
GTK_TREE_MODEL (a)
is basically just a way of writing
(GtkTreeModel *)a
But at the same time checking that 'a' really is a pointer to
a tree model.
For this reason,
GTK_TREE_MODEL (&list)
Can't work, since &list *isn't* a pointer to a tree model, it's
a pointer to the location where a pointer to the returned
tree model will be stored. You could just use the straight C cast
(GtkTreeModel **)&list
Or you could use a temporary variable of type GtkTreeModel.
gtk_tree_selection_get_selected (..., &model, ...);
list = GTK_TREE_MODEL (model);
Regards,
Owen
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]