Re: Reuse of a gtk_tree_model_get() Pointer



On Sat, Jan 23, 2010 at 11:43:22AM -0500, dhk wrote:
How can I reuse a pointer that was used in a call to gtk_tree_model_get()?

For example a call like gtk_tree_model_get(tmdl, &iter, INDEX, &rxi.idx,
QUANTITY, &rxi.qty, DESCRIPTION, &rxi.sdesc, -1);

If I wanted to add or change the description, depending upon whether
rxi.sdesc is NULL or not, should I free rxi.sdesc and allocate space for
the new string and then do a string copy?

gtk_tree_model_get() always gives you a copy of the string that you
*must* *free*.  Since it's a copy no change to it has any effect on the
stored data.

If you don't want copies you can declare string columns as
G_TYPE_POINTER but you have to provide cell renderers as the tree view
does not know how to display pointers and you have to ensure the strings
are freed when rows are removed/changed or the model destroyed.

In any case you use gtk_(list|tree)_store_set() to change the stored
data.

Alternatively, you can store pointers to structs (or objects) in the
store and then you change the struct (object) data by whatever means are
appropriate and emit the "row-changed" signal.

Yeti




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]