Qt-interest Archive, May 2007
Qt layout Q.
Message 1 in thread
Hello, everybody.
I've just encountered a problem and can't find a quick and easy solution (Qt 4.2.3/Win32)
Short description:
I have QWidget *w, already populated with nested child controls and layouts.
I want to insert MyCoolWidget *cw in top part of widget w (of course,
this required new v-box layout for w, managing cw and "old" layout).
Unfortunatelly, i can't do this in a simple manner:
QVBoxLayout *nl = new QVBoxLayout;
nl->setMargin(0);
nl->setSpacing(0);
nl->addWidget( cw );
QLayout *cl = w->layout();
QLayout *ll = 0;
if ( cl->inherits( "QVBoxLayout" ) )
ll = new QVBoxLayout;
else if ( cl->inherits( "QHBoxLayout" ) )
ll = new QHBoxLayout;
else
Q_ASSERT( false );
ll->setMargin( cl->margin() );
ll->setSpacing( cl->spacing() );
while ( cl->count() > 0 )
{
QLayoutItem *li = cl->takeAt(0);
ll->addItem( li );
qDebug( "Transfer layout item %p\n", li );
}
Q_ASSERT( cl->count() == 0 );
nl->addItem( ll );
delete cl;
w->setLayout( nl );
This code crashes at last line (setting new layout)
Call stack:
G2.exe!QLayoutPrivate::reparentChildWidgets(QWidget * mw=0x0012fcdc) Line 747 + 0xb C++
G2.exe!QLayoutPrivate::reparentChildWidgets(QWidget * mw=0x0012fcdc) Line 760 C++
G2.exe!QWidget::setLayout(QLayout * l=0x01401a50) Line 6936 C++
Any suggestions?
--
[ signature omitted ]