Dear Yann,

You can load data to tree store from a worker thread. I have done this once where I am populating a tree store form a jumbo XML file and showing percentage of loading on the UI. I suppose you are also looking for the same.

For cooking this dish you'll need the following.

1. A UI thread (which you already have),
2. A worker thread to parse the file and add data to tree store
3. a Glib::Dispatcher to send completion status updates from worker
   thread to UI thread
4. A member variable in your class where the worker thread shares the
   completion status and
5. a Glib::Mutex to protect to shared resource.

And this is how you cook it.

1. Create a member function and connect it to the Glib::Dispatcher
   object. This function starts with a Glib::Mutex::Lock and displays
   the percentage completion.
2. Disconnect the tree view from the tree store. Leaving it connected
   brings you serious speed issues and additionally its not a good idea
   to control any UI element from within a thread other than the main
   thread (gdk_threads_enter and leave never helped me! may be I was
   doing something wrong altogether).
3. Start a worker thread (implemented as a private member function of
   the same class) passing it the file from which to load.
4. Update the completion variable from the worker thread and trigger
   the Glib::Dispatcher object as you progress (don't forget about
   Glib::Mutex::Lock). I would do this once in 250 milliseconds.
5. Once your loading is complete, connect the tree store back to the
   tree view.

This should get you started.



regards

*Mohith Manoj*,
Asst. Manager (R&D),
Skanray Technologies PVT.LTD
Web:www.skanray.com  <http://www.skanray.com>

On 8/2/2013 6:47 PM, Yann Leydier wrote:
Thanks Kevin.

I know of the dispatcher but the problem is that I need to fill a TreeStore: the data is very complex and hard to send through a dispatcher.

Does anyone know if filing a store that is not bound to any TreeView would be ok (out of the main thread, I mean)? Is so, I could just swap the TreeView's store with the new one.

Thanks
yann

On 02/08/13 15:10, Kevin Brightwell wrote:
I'm not entirely sure of your problem, but I do know that GTK does not guarantee *any* thread safety for it's components. You should not be modifying the TreeView outside the UI thread. If this is how GTK manifests this problem, so be it. There is a Glib::Dispatcher() [1] [2] which would allow you to spawn the dispatcher in the UI thread, then push things from a worker thread and make sure the value gets updated on the UI.

I hope I'm actually helping the problem and not just being critical on style. :(

Cheers,

Kevin

[1] https://developer.gnome.org/glibmm/2.35/classGlib_1_1Dispatcher.html
[2] https://developer.gnome.org/gtkmm-tutorial/3.8/sec-using-glib-dispatcher.html.en



On Fri, Aug 2, 2013 at 8:51 AM, Yann Leydier <[email protected] <mailto:[email protected]>> wrote:

    Hi,

    my application fills some TreeStrores and ListStores at runtime
    but the data is read from large files and the computation of some
    values takes time. Therefore I put a progress bar in a splash
    window and fill the store in another thread.

    The TreeView fills oddly: once the lines do not fit anymore on
    the display, the scollbar is not updated. I tried to add
    gdk_threads_entrer() and gdk_threads_leave() before and after the
    calls to XXXStore::append() but it did not change anything.

    First question: are the stores really thread unsafe? I tend to
    consider them as non-UI classes, so TreeView should be the one
    handling the thread-safety...

    Second question: how do I make sure I do not mess up with the
    thread safety when filling my stores?

    Thanks a lot,
    yann
    _______________________________________________
    gtkmm-list mailing list
    [email protected] <mailto:[email protected]>
    https://mail.gnome.org/mailman/listinfo/gtkmm-list




--
Kevin Brightwell
/BESc. and BSc. Candidate 2015/
Western University www.westernu.ca <http://www.uwo.ca>
e. [email protected] <mailto:[email protected]> c. 226.678.4927



_______________________________________________
gtkmm-list mailing list
[email protected]
https://mail.gnome.org/mailman/listinfo/gtkmm-list



---
avast! Antivirus: Inbound message clean.
Virus Database (VPS): 130802-2, 08/03/2013
Tested on: 8/3/2013 9:05:39 AM
avast! - copyright (c) 1988-2013 AVAST Software.
http://www.avast.com








---
avast! Antivirus: Outbound message clean.
Virus Database (VPS): 130804-1, 08/05/2013
Tested on: 8/5/2013 10:39:46 AM
avast! - copyright (c) 1988-2013 AVAST Software.
http://www.avast.com


_______________________________________________
gtkmm-list mailing list
[email protected]
https://mail.gnome.org/mailman/listinfo/gtkmm-list

Reply via email to