[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-devel
Subject:    Re: Dynamically creating buttons
From:       David Jarvie <djarvie () kde ! org>
Date:       2008-06-13 0:30:39
Message-ID: 200806130130.39630.djarvie () kde ! org
[Download RAW message or body]

On Thu 12 June 2008 21:02:14 Anders Lövgren wrote:
> On Thursday 12 June 2008 20.01.25 Robert Wood wrote:
> >> You just need to store the enButtonGroup somewhere so it can be
> >> accessed here,  and then use the QButtonGroup API (Qt3: find(int), Qt4:
> >> button(int)) to fetchthe index-th button in the group. <<
> >
> > Maybe I misunderstand what you mean, but it's not the group that's the
> > problem. It was the individual button data I wanted to get at.
>
> Following Pino's suggestion, you should make QButtonGroup *enButtonGroup a
> member of the class and rewrite enChanged() something like this:
>
> void parametersdialogue::enChanged(int index)
> {
>     QString st = enButtonGroup->button(index)->text();  // Qt4
>     SendValue(st,index);
> }
>
> The QRD variable has local scope, so you can't use it outside of the
> function its declared in (hence the error message about its scope).

Pino's suggestion to use the QButtonGroup to access the individual buttons is 
the right solution in this case. But in other contexts (i.e. when you are not 
dealing with a group of buttons), if you have a variable number of QWidgets 
(or other pointers) to store, you should use QList<QWidget*> instead of an 
array of QWidget* values. QList<> is designed for such purposes, and is the 
standard KDE/Qt way of holding such data.
 
-- 
David Jarvie.
KAlarm author and maintainer.
http://www.astrojar.org.uk/kalarm
 
>> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic