Dear Albrecht and Roman,
Thank you both for your thorough answers to my question. Now I have a clue on
what I could/need to do. Basically, from what I understand from your
elaborations, there are (at least) three ways to approach this:
1- Passing a pointer of the widget to the member variable (member class) and
store it as a member variable inside the class.
2- Add a timeout callback using Fl::add_timeout(0, &timeout_callback, widget)
and update the widget inside the callback with a pre-defined rate, or
3- derive the desired class from a FLTK widget class and define the callback
inside the class and connect the callback to the widget through the fltk
callback mechanism.
Thanks again,
--Moslem.
> Moslem Kazemi wrote:
> > Hi fltkers,
> >
> > I am a newbie! :) and am trying to see if fltk would suit my application
> > needs. I would appreciate your help re. the following question.
>
> Welcome to the FLTK world !
>
> > I try to pose my question through a simple example as follows:
> > Let's say I have a fltk window with a text output widget and a member
> > variable which itself is a class, say a timer.
>
> Hmm, a member variable of what? If you mean the window, then this would
> probably be called a "child (widget)" of the window in FLTK, unless you
> want to derive your own window class, which would not be necessary in
> this case.
>
> > I would like to see what is the proper way that I could access/update the
> > value of the text output widget from within the methods of the class timer?
> > Should I pass a pointer of the text widget to the timer class?
>
> Yes, I think so. This would be the easiest way to do what you want. Of
> course this could also be a global variable, but passing a pointer to
> your own class (and saving it as a member variable) would do it.
>
> > Is there way that I could post a message from within the methods in timer
> > class to the main window and ask to update the widget value?
>
> There is no signal/slot mechanism or similar in FLTK, but maybe you can
> use the callback mechanism, something like:
>
> text_output = new Fl_Text_Output(...); // your text output widget
>
> timer = new MyTimerClass (...); // your timer class (*)
> timer->callback(my_callback,text_output);
>
> (*) the timer class would need to be derived from a FLTK widget class
> for this to work.
>
> This "connects" your callback function to the timer widget, and your
> callback can access the text output widget via its second argument:
>
> void my_callback (Fl_Widget *w, void *p) {
>
> // w = pointer to your timer class
>
> text_output = (Fl_Text_Output *)p;
> ...
> }
>
> .... and as Roman wrote, you can also use FLTK's internal timer events if
> you like. The mechanism is similar: you can set the callback argument
> you need via Fl::add_timeout().
>
> Albrecht
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk