QLayout: add className() to a warning message

Since objectName() isn't always set, the className() makes it slightly
easier to find and fix the issue.

Also unify some wording "produce a warning", which is generic enough to
fit:
print warning in terminal
print warning in logviewer (if you're unlucky and have to use Windows?)
print warning in system journal (if you're unlucky have to use binary
systemd journal logs)

Change-Id: I7522d65666cb5829c33c45039b8646dd535e21ea
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
(cherry picked from commit 60c69b4da52b4b90e74af569c859c992e8e910fe)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Ahmad Samir 2022-06-26 14:08:50 +02:00 committed by Qt Cherry-pick Bot
parent f33f6ddada
commit b3a6136000
3 changed files with 13 additions and 12 deletions

View File

@ -709,24 +709,24 @@ QLayout::~QLayout()
/*!
This function is called from \c addLayout() or \c insertLayout() functions in
subclasses to add layout \a l as a sub-layout.
subclasses to add layout \a childLayout as a sub-layout.
The only scenario in which you need to call it directly is if you
implement a custom layout that supports nested layouts.
\sa QBoxLayout::addLayout(), QBoxLayout::insertLayout(), QGridLayout::addLayout()
*/
void QLayout::addChildLayout(QLayout *l)
void QLayout::addChildLayout(QLayout *childLayout)
{
if (Q_UNLIKELY(l->parent())) {
qWarning("QLayout::addChildLayout: layout \"%ls\" already has a parent",
qUtf16Printable(l->objectName()));
if (Q_UNLIKELY(childLayout->parent())) {
qWarning("QLayout::addChildLayout: layout %s \"%ls\" already has a parent",
childLayout->metaObject()->className(), qUtf16Printable(childLayout->objectName()));
return;
}
l->setParent(this);
childLayout->setParent(this);
if (QWidget *mw = parentWidget()) {
l->d_func()->reparentChildWidgets(mw);
childLayout->d_func()->reparentChildWidgets(mw);
}
}
@ -829,9 +829,10 @@ bool QLayoutPrivate::checkLayout(QLayout *otherLayout) const
This function is called from \c addWidget() functions in
subclasses to add \a w as a managed widget of a layout.
If \a w is already managed by a layout, this function will give a warning
and remove \a w from that layout. This function must therefore be
called before adding \a w to the layout's data structure.
If \a w is already managed by a layout, this function will produce
a warning, and remove \a w from that layout. This function must
therefore be called before adding \a w to the layout's data
structure.
*/
void QLayout::addChildWidget(QWidget *w)
{

View File

@ -116,7 +116,7 @@ void tst_QBoxLayout::insertLayout()
QCOMPARE(dummyParentLayout->count(), 1);
// add subLayout to another layout
QTest::ignoreMessage(QtWarningMsg, "QLayout::addChildLayout: layout \"\" already has a parent");
QTest::ignoreMessage(QtWarningMsg, "QLayout::addChildLayout: layout QHBoxLayout \"\" already has a parent");
vbox->addLayout(subLayout);
QCOMPARE((subLayout->parent() == vbox), (vbox->count() == 1));
}

View File

@ -1065,7 +1065,7 @@ void tst_QFormLayout::setLayout()
// should be ignored and generate warnings
QTest::ignoreMessage(QtWarningMsg, "QFormLayoutPrivate::setItem: Cell (3, 1) already occupied");
layout.setLayout(3, QFormLayout::FieldRole, &l4);
QTest::ignoreMessage(QtWarningMsg, "QLayout::addChildLayout: layout \"\" already has a parent");
QTest::ignoreMessage(QtWarningMsg, "QLayout::addChildLayout: layout QHBoxLayout \"\" already has a parent");
layout.setLayout(-1, QFormLayout::FieldRole, &l4);
QCOMPARE(layout.count(), 3);
QCOMPARE(layout.rowCount(), 6);