cocalele
24th April 2006, 07:21
Hi,
I just find a assert failure when I use QLayout. I want know is this a bug of QLayout.
The QLayout has a constructor like this, which need a parent of QWdiget
QLayout::QLayoutQWidget *parent)
: QObject(*new QLayoutPrivate, parent)
{
if (!parent)
return;
parent->setLayout(this);
}
But in the code of QLayout::parentWidget() (line 6), it trys to cast the parent to QLayout
QWidget *QLayout::parentWidget() const
{
Q_D(const QLayout);
if (!d->topLevel) {
if (parent()) {
QLayout *parentLayout = ::qobject_cast<QLayout*>(parent());
Q_ASSERT(parentLayout);
return parentLayout->parentWidget();
} else {
return 0;
}
} else {
Q_ASSERT(parent() && parent()->isWidgetType());
return static_cast<QWidget *>(parent());
}
}
certainly, cast from QWidget* to QLayout* will failled, and the successed assertion will failed. Is this a bug or anything I don't know?
Thanks for your help!
I just find a assert failure when I use QLayout. I want know is this a bug of QLayout.
The QLayout has a constructor like this, which need a parent of QWdiget
QLayout::QLayoutQWidget *parent)
: QObject(*new QLayoutPrivate, parent)
{
if (!parent)
return;
parent->setLayout(this);
}
But in the code of QLayout::parentWidget() (line 6), it trys to cast the parent to QLayout
QWidget *QLayout::parentWidget() const
{
Q_D(const QLayout);
if (!d->topLevel) {
if (parent()) {
QLayout *parentLayout = ::qobject_cast<QLayout*>(parent());
Q_ASSERT(parentLayout);
return parentLayout->parentWidget();
} else {
return 0;
}
} else {
Q_ASSERT(parent() && parent()->isWidgetType());
return static_cast<QWidget *>(parent());
}
}
certainly, cast from QWidget* to QLayout* will failled, and the successed assertion will failed. Is this a bug or anything I don't know?
Thanks for your help!