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
: QObject(*new QLayoutPrivate, parent
) {
if (!parent)
return;
parent->setLayout(this);
}
QLayout::QLayoutQWidget *parent)
: QObject(*new QLayoutPrivate, parent)
{
if (!parent)
return;
parent->setLayout(this);
}
To copy to clipboard, switch view to plain text mode
But in the code of QLayout:arentWidget() (line 6), it trys to cast the parent to 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());
}
}
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());
}
}
To copy to clipboard, switch view to plain text mode
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!
Bookmarks