[Qt-interest] problem in QWidget type cast

Andre Haupt andre at bitwigglers.org
Tue Aug 11 08:04:41 CEST 2009


On Tue, Aug 11, 2009 at 04:37:12PM +0530, Chandru... wrote:
> hi friends,
> 
> i got a problem in QList
> as i subject all my object in a Widget class to a QList by
> 
> "*QList wlist;
>  wlist = embed->findChildren<QWidget *>()*;"
> 
> this list have QLabel, QTextEdit, etc ..
> but all were typecast to QWidget in the QList ..
> 
> now i want to access a label in wlist.at(2) .. which currently returning a
> QWidget pointer ..
> 
> where to use qobject_cast?
> how to call a typical QLabel function ex:setText on the QList item with type
> cast ..

does thus help?

QLabel *label = qobject_cast<QLabel *>(wlist.at(2));
if (label)
	label->setText("bla");


regards,

Andre



More information about the Qt-interest-old mailing list