Re: Signals in threads



Hi Mike,

You could have a seperate class with the dispatcher and the thread
function and add an instance of it as a member of whichever class you
need the thread in.

That's the way its done in the dispatcher example:

http://gtkmm.sourceforge.net/docs/glibmm-2.4/examples/thread/dispatcher.cc

Regards,
Klaus

On 12/08/2007 18:33, AxeTota wrote:
> Hi, I stumbled on this post trying to figure out how to use Glib::Thread and
> dispatcher.... how do you make the 'worker thread' aware of the
> Glib::Dispatcher?? should the threaded function be a member of the GUI class
> or should the dispatcher be passed as an argument to the tread function... I
> am new to this type of thing (using threads) so i'm not sure how to approach
> it.
>
> I have it working by having the thread function as a member in my GUI class. 
> However, I prefer not to do that as I might need to use that function
> somewhere else and would rather have it in a different class that could be
> used in other dialogs/windows in my app.  any suggestions are much
> appreciated.
>
> thanks in advance,
> mike
>
>
> Robert Caryl wrote:
>   
>> Hey Mike:
>>
>> First, you need to declare a Gtk::Dispatcher object in your GUI class.  
>> It will be the conduit from your worker threads to your GUI (and usually 
>> primary) thread.  Next, in your GUI class you declare a function to 
>> handle the data coming from your worker thread that you will use to 
>> update your GUI, and you use it as a callback slot to connect to your 
>> Gtk::Dispatcher:
>>
>> Gtk::Dispatcher my_dispatcher;
>> my_dispatcher.connect(sigc::mem_fun(*myclass,&MyClass::my_callback_slot));
>>
>> Then, in the worker thread, you just call the dispatcher as a function:
>>
>> my_dispatcher();
>>
>> whenever you wish to update your GUI. 
>>
>> In my case, I had also declared in my GUI class a 
>> std::vector<Glib::ustring> object to which my worker thread pushed back 
>> string data that I wanted to add to a Gtk::TextBuffer displayed in a 
>> Gtk::TextView in my GUI class.  My callback slot would pop the 
>> Glib::ustrings off this vector one at a time and add them to the 
>> Gtk::TextBuffer whenever it was called by the dispatcher.  Therefore, my 
>> worker thread would push back strings to this vector object just prior 
>> to calling the dispatcher.
>>
>> I hope this helps.
>>
>> Bob
>>
>> /*Bob Caryl*
>> Fiscal Systems,Inc.
>> 256.772.8920 Ext. 108
>> http://www.fis-cal.com <http://www.fis-cal.com/>/
>>
>> /This email message may contain privileged or confidential information. 
>> If you are not the intended recipient, you may not disclose, use, 
>> disseminate, distribute, copy or rely on this message or attachment in 
>> any way. If you received this email message in error, please return by 
>> forwarding the message and its attachment to the sender and then delete 
>> the message and its attachment from your computer.
>>
>> Neither Fiscal Systems, Inc., nor its affiliates, accept any liability 
>> for any errors, omissions, corruption or virus in the contents of this 
>> message or any attachments that arise as a result of e-mail transmission./
>>
>>
>>
>> Mike Polan wrote:
>>     
>>> Hi,
>>> I need to emit certain signals inside a running Glib::Thread in order 
>>> to relay some information to the rest of my app. However, from what I 
>>> know, I don't believe that it is really safe to emit such signals that 
>>> are connected to a Gtk::Window, which in turn will call some GUI 
>>> functions, directly from inside threads. Someone mentioned something 
>>> about Glib::Dispatcher to me, but I'm not quite sure if that's what's 
>>> needed to accomplish my task. In any case, how would I go about doing 
>>> something like this?
>>>
>>> Thanks in advance.
>>> ------------------------------------------------------------------------
>>>
>>> _______________________________________________
>>> gtkmm-list mailing list
>>> gtkmm-list gnome org
>>> http://mail.gnome.org/mailman/listinfo/gtkmm-list
>>>   
>>>       
>> 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
>>
>>
>> _______________________________________________
>> gtkmm-list mailing list
>> gtkmm-list gnome org
>> http://mail.gnome.org/mailman/listinfo/gtkmm-list
>>
>>
>>     
>
>   




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