Re: GTKEntry, need help with Multi-Threading & GUI Updating....
- From: Allen <allen saucier cas-inc com>
- To: Nickolai Dobrynin <ndobrynin gmail com>
- Cc: gtkmm-list gnome org
- Subject: Re: GTKEntry, need help with Multi-Threading & GUI Updating....
- Date: Mon, 30 Oct 2006 13:43:03 -0600
Hello Nickolai, & everyone else,
I've found a GREAT solution to the problem I described about how to
update a GUI Dialog running in a "main thread" while it was receiving
data from another Thread w/in the same process in GTKMM
Simple, really. Here's the code:
.h
class Class
{
// glib connection for a timer
//
sigc::connection m_con; ///< Timer Connection
// Update GUI Method
//
bool m_bUpdateGUI(void)
{ // Update Interface
//
while( Gtk::Main::events_pending() )
Gtk::Main::iteration(false);
return true;
}; ///< returns true so that timer is not halted
}; // Class
.cpp
ClassCclass()
{
// Set up Timer
//
m_con = Glib::signal_timeout().connect( sigc::mem_fun( *this,
&CCramWinMain::m_bUpdateGUI ), 100 );
} // ctor
Explanation:
1st - declare the sigc::connection m_con; Attribute of the class &
declare the bool m_bUpdateGUI(void); Method which is used
as the primary call back for the timer.
2nd - in the class's constructor (ctor), set up the connection:
m_con = Glib::signal_timeout().connect( sigc::mem_fun(
*this, &CCramWinMain::m_bUpdateGUI ), 100 );
That's it. Now my GUI is updated often enough so that the data from the
Secondary Thread, when it is passed to the primary Thread, is properly
updated w/in the GTK::Entry field I'm using as the display field.
Took me a while to figure this one out but it sames me from getting a
gtkmm error message about the 'update' method being in another Thread
and then the program crashing because the Secondary thread is calling
the Primary Thread's UpdateGUI method. Gtkmm doesn't like that.
Thanks all!!! And thank you Nickolai for emailing me! I really
appreciate your help. :-)
Nickolai Dobrynin wrote:
Allen,
As far as threading goes, the following should help:
http://www.gtkmm.org/docs/gtkmm-2.4/docs/FAQ/html/index.html#id2516102
Scroll down to 4.12.
Also, let me get this straight: the way you set things up is by having
your other thread generate numeric
data, which you then pass to the GUI thread (however that's done) for
displaying. If my understanding is correct,
then you shouldn't need anything like
while( Gtk::Main::events_pending() )
Gtk::Main::iteration(false);
If all else is done right, set_text(...) will do the job.
Regards,
Nickolai
--
Sincerely, Allen
Gene Allen Saucier, Jr
Senior Software Engineer
CAS, Inc
100 Quality Circle
Huntsville, AL 35806
or
PO Box 11190
Huntsville, AL 35814
(256) 922-6453 (w)
"As for I and my house, we shall follow the Lord" Joshua 25:14
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]