Developing Programmers .com

Local Search:


SyncUp8 is rethinking research. Find out more.


This site is optimized for standards so you can use any standards compliant browser:

Valid XHTML 1.0 Transitional
Valid CSS!
(RSS) RSS Feed

Web Search:
Google


Monday, 4 July, 2011

Qt Trick  

I was looking for a simple way to delete all subwidgets and layout from a Qt container widget today.

Mark pointed me to a post that suggested a method, and I thought others might benefit from a code example of how I ended up solving this.

void MyWidget::clearSubWidgets()
{
    QObjectList ch = children();
    foreach (QObject *o, ch)
    {
        QObject *todel = qobject_cast<QWidget *>(o);
        if (!todel)
            todel = qobject_cast<QLayout *>(o);
        if (todel)
            delete todel;
    }
}

Feel free email in suggested improvements :)

Posted by sarah at 5:14 pm in: Libraries (20490 views)

0 Comments

Please use the DP Forums for further discussion of this topic.