GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Wed Apr 16, 2014 4:22 pm

All times are UTC




Post new topic Reply to topic  [ 19 posts ]  Go to page Previous  1, 2
Author Message
 Post subject: Re: How to remove (unset) values from TreeModel
PostPosted: Tue Jul 02, 2013 6:11 am 
Offline
Never Seen the Sunlight

Joined: Mon Apr 28, 2008 5:52 am
Posts: 709
Location: UK
Hi,

Been very busy.

The C++ bindings allow you to do things slightly differently to make things easier which is what I am more used to. I would create a blank image and pass that if you want to clear the image.

Checking the source to GTK+ the is no way to pass a NULL value.

_________________
E.


Top
 Profile  
 
 Post subject: Re: How to remove (unset) values from TreeModel
PostPosted: Tue Jul 02, 2013 7:30 am 
Offline
Familiar Face

Joined: Mon Dec 21, 2009 4:36 pm
Posts: 22
But blank image also consumes memory... I would like to clear it. And what about icon, how to set empty icon? I tried to browse source code, but didn't find any solution. It looks like model doesn't allow null values at all.


Top
 Profile  
 
 Post subject: Re: How to remove (unset) values from TreeModel
PostPosted: Wed Jul 03, 2013 7:08 am 
Offline
Never Seen the Sunlight

Joined: Mon Apr 28, 2008 5:52 am
Posts: 709
Location: UK
Been doing a bit more reading up. Yes you can pass a NULL as a value for a GObject to clear out an image in a Tree View.

This is an example taken from the tree view tutorial.
Code:
  GtkListStore *list_store;
  GtkTreeIter   iter;
  GdkPixbuf    *pixbuf;
  GError       *error = NULL;

  list_store = gtk_list_store_new (2, GDK_TYPE_PIXBUF, G_TYPE_STRING);

  pixbuf = gdk_pixbuf_new_from_file("icon.png", &error);

  /* pixbuf has a refcount of 1 after creation */

  if (error)
  {
    g_critical ("Could not load pixbuf: %s\n", error->message);
    g_error_free(error);
    return;
  }

  gtk_list_store_append(list_store, &iter);

  gtk_list_store_set(list_store, &iter, 0, pixbuf, 1, "foo", -1);

  /* pixbuf has a refcount of 2 now, as the list store has added its own reference */

  g_object_unref(pixbuf);

  /* pixbuf has a refcount of 1 now that we have released our initial reference */

  /* we don't want an icon in that row any longer */
  gtk_list_store_set(list_store, &iter, 0, NULL, -1);

  /* pixbuf has automatically been destroyed after its refcount has reached 0.
   *  The list store called g_object_unref() on the pixbuf when it replaced
   *  the object in the store with a new value (NULL). */


Also using a single blank image will not consume that much memory as what you should be doing is reusing the same image and what GTK will do is add to the reference count how many times it is used.

With out seeing any of your code it is very hard to tell what is going on and why you are getting the errors.

_________________
E.


Top
 Profile  
 
 Post subject: Re: How to remove (unset) values from TreeModel
PostPosted: Wed Jul 03, 2013 7:27 am 
Offline
Familiar Face

Joined: Mon Dec 21, 2009 4:36 pm
Posts: 22
errol
Thank you very much! It works! really works! :-)
I just used wrong function to set null values. I used gtk_list_store_set_value instead of gtk_list_store_set. The first function doesn't accept nulls while the second one does! I think TreeStore functions works in the same fashion. Unfortunately I didn't find this in documentation. Live and learn :-)


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 19 posts ]  Go to page Previous  1, 2

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group