Re: signal_timeout vs loops (changing label text continuously)



The docs page for Glib::Thread is http://www.gtkmm.org/docs/glibmm-2.4/docs/reference/html/classGlib_1_1Thread.html

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:

while(Gtk::Main::events_pending())
    Gtk::Main::iteration();

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 <http://www.gtkmm.org/docs/glibmm-2.4/docs/reference/html/classGlib_1_1Dispatcher.html> for more information on how to do this. <http://www.gtkmm.org/docs/glibmm-2.4/docs/reference/html/classGlib_1_1Dispatcher.html>

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?

Thanks,
-Gezim


begin:vcard
fn:Robert Caryl
n:Caryl;Robert
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
x-mozilla-html:TRUE
url:http://www.fis-cal.com
version:2.1
end:vcard



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