Re: How to use specific methods with a generic widget pointer?
- From: Paulo Flabiano Smorigo <pfsmorigo gmail com>
- To: jody <jody xha gmail com>
- Cc: gtkmm-list <gtkmm-list gnome org>
- Subject: Re: How to use specific methods with a generic widget pointer?
- Date: Tue, 17 Mar 2009 12:32:03 -0300
On Tue, Mar 17, 2009 at 12:05, jody <jody xha gmail com> wrote:
> Sorry
> I forgot to send this to the list
>
> As Guillaume said, set_active is specific to Gtk::ToggleButton and
> derived classes.
> So if you don't want (or cant) use set_active() directly, you could
> use a pointer to Gtk::ToggleButton instead of a pointer to Gtk::Widget* :
> Gtk::ToggleButton btnOK;
> Gtk::ToggleButton *ptrElement = NULL;
>
> ptrElement = &btnOK;
>
> ptrElement->set_active(true);
>
> If your pointer sometimes points at other kinds of Widgets, you could
> still use a pointer to Gtk::Widget, and then cast it to a pointer to
> Gtk::ToggleButton before using it:
>
> dynamic_cast<Gtk::ToggleButton *>(ptrElement)->set_active(true);
>
> Keep in mind that this will give you an error if at that moment
> ptrElement does not point to a Gtk::ToggleButton (or descendant)
>
>
> Jody
>
> On Tue, Mar 17, 2009 at 3:58 PM, Paulo Flabiano Smorigo
> <pfsmorigo gmail com> wrote:
>> On Tue, Mar 17, 2009 at 11:40, Guillaume Brocker
>> <guillaume brocker digital-trainers com> wrote:
>>> Paulo Flabiano Smorigo a écrit :
>>>>
>>>> Hello,
>>>>
>>>> What can I do to solve the following error? I need to use a different
>>>> kind of pointer?
>>>>
>>>> The code:
>>>> Gtk::ToggleButton btnOK;
>>>> Gtk::Widget *ptrElement = NULL;
>>>>
>>>> ptrElement = &btnOK;
>>>>
>>>> ptrElement->set_active(true);
>>>>
>>>> The error:
>>>> error: ‘class Gtk::Widget’ has no member named ‘set_active’
>>>
>>> Gtk::Widget has no member ‘set_active’. This member is specific to
>>> Gtk::ToggleButton and derived classes. Wy don't you call ‘btnOK.set_active’
>>> directly ?
>>>
>>>> Thanks in advance,
>>>> Paulo Flabiano Smorigo
>>>
>>> Guillaume
>>>
>>
>> Hi Guillaume,
>>
>> Thanks for the fast reply...
>>
>> I know that the Gtk::Widget don't have the set_active() member but as
>> it is pointing to a ToggleButton widget, isn't it possible to use the
>> method?
>>
>> I there a someway to make the pointer accept the method?
>>
>> Thanks...
>> Paulo Flabiano Smorigo
>> _______________________________________________
>> gtkmm-list mailing list
>> gtkmm-list gnome org
>> http://mail.gnome.org/mailman/listinfo/gtkmm-list
>>
>
Hi everyone,
Thanks for the help! It works. I put a validation to test if it is an
ToggleButton before.
Thanks again,
Paulo Flabiano Smorigo
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]