Re: signal_timeout vs loops (changing label text continuously)

The docs page for Glib::Thread is

Basically, to use a "thread" you first write a function to do the work you wish to have done outside the GUI thread. Then you create the thread using

Glib::Thread *my_thread = Glib::Thread::create(sigc::mem_fun(*this,&YourClass::your_thread_function),false);

Then, your function will be executed by that thread and the thread will exit when your function returns. In my example the function that is passed to Glib::Thread::create is a member of a class, but you do not have to do that if you do not want to; you can use sigc::ptr_fun() instead:

Glib::Thread *my_thread = Glib::Thread::create(sigc::ptr_fun(&your_thread_function),false);

Hope this helps,

Bob Caryl

Gezim Hoxha wrote:
On Tue, 2006-27-06 at 08:41 -0500, Bob Caryl wrote:
Anytime you create a "loop" in the GUI thread, all GUI operations (including your call to Gtk::Label::set_text()) are suspended until your loop finishes and the function in which it runs returns. You must allow Gtk::Main to do its job at some point during your loop iteration by inserting the following statements:


After your call to Gtk::Label::set_text(). This will allow the GUI to update. However, you should always avoid doing this sort of processing in the GUI thread. A well written application will do such processing in a separate thread and use a Gtk::Dispatcher to update the GUI if needed. See Gtk::Dispatcher <> for more information on how to do this. <>

Thanks alot for your answer Bob. Also thanks to Leandro Fanzone.

You keep mentioning threads, but unfortunately I don't know anything
about them. Which book should I pick up?


fn:Robert Caryl
org:Fiscal Systems, Inc.
adr:;;102 Commerce Circle;Madison;AL;35758;USA
email;internet:bob fis-cal com
title:Senior Software Design Engineer
tel;work:356-772-8920 X108

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