Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 3

Qt-interest Archive, May 2008
How to iterate through widgets in QStackWidget?


Message 1 in thread

I have several different kind of panels stacked together inside one 
QStackedWidget. I need to modify settings on all panels of one kind. My 
problem is - I do not know how to get the real type of widget?
---------------------------
class PanelA : public QWidget {....};
class PanelB : public QWidget {....};
extern QStackedWidget *stack;
// stack is created and filled up somewhere with unknown number of PanelA 
and PanelB widgets

for (int i; i<stack->count(); i++) {
   QWidget *panel = stack->widget(i);
   if ( panel ...... is of class PanelA ) {   // how to do this condition???
      PanelA *panelA = qobject_cast<PanelA*>(panel);
      panelA->someFunctionOfA();
   }
}
---------------------------  


--
 [ signature omitted ] 

Message 2 in thread

Hi,

Check
http://doc.trolltech.com/4.4/qobject.html#qobject_cast
qobject_cast, like dynamic_cast, will return 0 if the cast was 
successful. Your code should look like this:

PanelA *panelA = qobject_cast<PanelA*>(panel);
if (panelA)
   panelA->someFunctionOfA();


Cheers,
Ian.

This email and any files transmitted with it are confidential and are intended solely for the use of the individual or entity to whom they are addressed.  If you are not the original recipient or the person responsible for delivering the email to the intended recipient, be advised that you have received this email in error, and that any use, dissemination, forwarding, printing, or copying of this email is strictly prohibited. If you received this email in error, please immediately notify the sender and delete the original.


--
 [ signature omitted ] 

Message 3 in thread

Correction: They return 0 if the cast is UNsuccessful, of course.

This email and any files transmitted with it are confidential and are intended solely for the use of the individual or entity to whom they are addressed.  If you are not the original recipient or the person responsible for delivering the email to the intended recipient, be advised that you have received this email in error, and that any use, dissemination, forwarding, printing, or copying of this email is strictly prohibited. If you received this email in error, please immediately notify the sender and delete the original.


--
 [ signature omitted ] 

Message 4 in thread

Thank you.

"Ian Thomson" <Ian.Thomson@xxxxxxxxxx> wrote in message 
news:482C6A8D.1090806@xxxxxxxxxxxxx
> Hi,
>
> Check
> http://doc.trolltech.com/4.4/qobject.html#qobject_cast
> qobject_cast, like dynamic_cast, will return 0 if the cast was successful. 
> Your code should look like this:
>
> PanelA *panelA = qobject_cast<PanelA*>(panel);
> if (panelA)
>   panelA->someFunctionOfA();
>
>
> Cheers,
> Ian.
>
> This email and any files transmitted with it are confidential and are 
> intended solely for the use of the individual or entity to whom they are 
> addressed.  If you are not the original recipient or the person 
> responsible for delivering the email to the intended recipient, be advised 
> that you have received this email in error, and that any use, 
> dissemination, forwarding, printing, or copying of this email is strictly 
> prohibited. If you received this email in error, please immediately notify 
> the sender and delete the original.
>
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with 
> "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
>
> 

--
 [ signature omitted ]