Fixed crash taking null central widget
When no central widget has been set, calling takeCentralWidget should just return a null pointer instead of crashing. [ChangeLog][QtWidgets][QMainWindow] Fixed crash using takeCentralWidget when the central widget was not set. Task-number: QTBUG-56628 Change-Id: I240ccf4caa41d2716a78851571fbfbf444a4922e Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
This commit is contained in:
parent
dbf35d7571
commit
4c00246fea
@ -664,8 +664,10 @@ QWidget *QMainWindow::takeCentralWidget()
|
|||||||
{
|
{
|
||||||
Q_D(QMainWindow);
|
Q_D(QMainWindow);
|
||||||
QWidget *oldcentralwidget = d->layout->centralWidget();
|
QWidget *oldcentralwidget = d->layout->centralWidget();
|
||||||
oldcentralwidget->setParent(0);
|
if (oldcentralwidget) {
|
||||||
d->layout->setCentralWidget(0);
|
oldcentralwidget->setParent(0);
|
||||||
|
d->layout->setCentralWidget(0);
|
||||||
|
}
|
||||||
return oldcentralwidget;
|
return oldcentralwidget;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -864,6 +864,10 @@ void tst_QMainWindow::takeCentralWidget() {
|
|||||||
|
|
||||||
QVERIFY(!mw.centralWidget());
|
QVERIFY(!mw.centralWidget());
|
||||||
|
|
||||||
|
// verify that we don't crash when trying to take a non-set
|
||||||
|
// central widget but just return a null pointer instead
|
||||||
|
QVERIFY(!mw.takeCentralWidget());
|
||||||
|
|
||||||
mw.setCentralWidget(w1);
|
mw.setCentralWidget(w1);
|
||||||
|
|
||||||
QWidget *oldCentralWidget = mw.takeCentralWidget();
|
QWidget *oldCentralWidget = mw.takeCentralWidget();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user