tags:

views:

204

answers:

1

Being resonably new to using GTK+, im not fully aware of all its functionality.

Basically, I have a GtkTreeView widget that has 4 Columns. I need to update the text displayed in the 4 columns every couple of seconds, but im not aware how to do this in GTK+.

I'm aware that I could flush the data using gtk_tree_store_clear, but I'm not sure how to repopulate the columns and have the top level window refresh to show this new data?

+1  A: 

You need to get a GtkTreeIter to the proper row, then use the appropriate (model-specific) setter to change the data.

For instance gtk_list_store_set() for the GtkListStore model.

There is no need to clear the entire model if you just want to change some of the data, that is very wasteful and slow.

If you really need to change all the data, then sure, clear it.

You don't have to worry about getting the display to refresh; the view listens to events from the model, and automatically knows to refresh when the model changes.

UPDATE:

When changing the data (as described in commment), you don't need to "flush" the old data. The model owns the data, and knows how to keep track of the memory used. You just use the above-mentioned gtk_list_store_set() call as necessary to put the new desired data in the model. You can do this as often as necessary, and an update frequency of once every few seconds should be no problem at all.

Of course, in such a case, to keep your application (which I assume is single-threaded, for simplicity) responsive, you must have a way to asynchronously trigger an update, perhaps using a timer. Have a look at glib's g_timeout_add() function to learn how to add a simple global timer.

unwind
ahhh, good to know, thanks for your help unwind
paultop6
im wondering if u can help me unwind. The problem im having is trying to place in the new data. I have to flush and replace the data every few seconds. Im worried im gonna ahve to have a function that is constantly looping, flushing and placing new data. How is it exactly that you flush the data from the columns and replace it, after you have called gtk_main?
paultop6
@paultop6: I've tried updating the answer to address those issues.
unwind
g_timeout_add() is perfect for what im looking to do, but im having trouble with what to pass it. The function i have is in a class, with its definitions looking like this: gboolean Sysmon::GenerateListStore(void)I call g_timeout_add like this:g_timeout_add(interval, GenerateListStore, NULL);which gives me the error:error: argument of type ‘gboolean (Sysmon::)()’ does not match ‘gboolean (*)(void*)’Im not sure how to meet the requirements that the error is telling me, perhaps you would know unwind?
paultop6
@pauktop6: Are you using plain C-based GTK+ API, or a C++ wrapper? In the former case, you need to define a (static) "trampoline" function in your C++ class, and pass the this pointer as the timeout's user_data pointer. The trampoline should do the cast and forward the call to the proper method.
unwind