QtWidgets: use Q_UNLIKELY for every qWarning() (2)

If, after checking a condition, we issue a qWarning(),
by definition that check is unlikely to be true.

Tell the compiler so it can move the error handling
code out of the normal code path to increase the
effective icache size.

This change contains the changes to the accessible/,
effects/, kernel/, styles/ and itemviews/ subdirs.

Moved conditional code around where possible so that
we could always use Q_UNLIKELY, instead of having to
revert to Q_LIKELY here and there.

In QWidgetPrivate::setWindowModified_helper(), as a
drive-by, I swapped the evaluation order of an
&&-expression (newly wrapped in Q_UNLIKELY) to be
more readable and more efficient (cheaper check
first) at the same time.

In qDraw* (qdrawutil.cpp), simplified boolean
expressions (sometimes by skipping re-checking
conditions already checked in a previous guard clause).

Change-Id: I58be22be0a33522c2629a66c2f6c795771a99f3f
Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
This commit is contained in:
Marc Mutz 2015-11-12 10:16:22 +01:00
parent 5645dc9f8a
commit 0325842b99
30 changed files with 109 additions and 109 deletions

View File

@ -132,7 +132,7 @@ QAccessibleInterface *QAccessibleTable::cellAt(int row, int column) const
return 0; return 0;
Q_ASSERT(role() != QAccessible::Tree); Q_ASSERT(role() != QAccessible::Tree);
QModelIndex index = view()->model()->index(row, column, view()->rootIndex()); QModelIndex index = view()->model()->index(row, column, view()->rootIndex());
if (!index.isValid()) { if (Q_UNLIKELY(!index.isValid())) {
qWarning() << "QAccessibleTable::cellAt: invalid index: " << index << " for " << view(); qWarning() << "QAccessibleTable::cellAt: invalid index: " << index << " for " << view();
return 0; return 0;
} }
@ -505,7 +505,7 @@ QAccessibleInterface *QAccessibleTable::child(int logicalIndex) const
if (!iface) { if (!iface) {
QModelIndex index = view()->model()->index(row, column, view()->rootIndex()); QModelIndex index = view()->model()->index(row, column, view()->rootIndex());
if (!index.isValid()) { if (Q_UNLIKELY(!index.isValid())) {
qWarning() << "QAccessibleTable::child: Invalid index at: " << row << column; qWarning() << "QAccessibleTable::child: Invalid index at: " << row << column;
return 0; return 0;
} }
@ -666,7 +666,7 @@ QModelIndex QAccessibleTree::indexFromLogical(int row, int column) const
return QModelIndex(); return QModelIndex();
const QTreeView *treeView = qobject_cast<const QTreeView*>(view()); const QTreeView *treeView = qobject_cast<const QTreeView*>(view());
if ((row < 0) || (column < 0) || (treeView->d_func()->viewItems.count() <= row)) { if (Q_UNLIKELY(row < 0 || column < 0 || treeView->d_func()->viewItems.count() <= row)) {
qWarning() << "QAccessibleTree::indexFromLogical: invalid index: " << row << column << " for " << treeView; qWarning() << "QAccessibleTree::indexFromLogical: invalid index: " << row << column << " for " << treeView;
return QModelIndex(); return QModelIndex();
} }
@ -776,7 +776,7 @@ int QAccessibleTree::indexOfChild(const QAccessibleInterface *iface) const
QAccessibleInterface *QAccessibleTree::cellAt(int row, int column) const QAccessibleInterface *QAccessibleTree::cellAt(int row, int column) const
{ {
QModelIndex index = indexFromLogical(row, column); QModelIndex index = indexFromLogical(row, column);
if (!index.isValid()) { if (Q_UNLIKELY(!index.isValid())) {
qWarning() << "Requested invalid tree cell: " << row << column; qWarning() << "Requested invalid tree cell: " << row << column;
return 0; return 0;
} }
@ -835,7 +835,7 @@ bool QAccessibleTree::selectRow(int row)
QAccessibleTableCell::QAccessibleTableCell(QAbstractItemView *view_, const QModelIndex &index_, QAccessible::Role role_) QAccessibleTableCell::QAccessibleTableCell(QAbstractItemView *view_, const QModelIndex &index_, QAccessible::Role role_)
: /* QAccessibleSimpleEditableTextInterface(this), */ view(view_), m_index(index_), m_role(role_) : /* QAccessibleSimpleEditableTextInterface(this), */ view(view_), m_index(index_), m_role(role_)
{ {
if (!index_.isValid()) if (Q_UNLIKELY(!index_.isValid()))
qWarning() << "QAccessibleTableCell::QAccessibleTableCell with invalid index: " << index_; qWarning() << "QAccessibleTableCell::QAccessibleTableCell with invalid index: " << index_;
} }

View File

@ -274,7 +274,7 @@ public:
void QAccessibleWidget::addControllingSignal(const QString &signal) void QAccessibleWidget::addControllingSignal(const QString &signal)
{ {
QByteArray s = QMetaObject::normalizedSignature(signal.toLatin1()); QByteArray s = QMetaObject::normalizedSignature(signal.toLatin1());
if (object()->metaObject()->indexOfSignal(s) < 0) if (Q_UNLIKELY(object()->metaObject()->indexOfSignal(s) < 0))
qWarning("Signal %s unknown in %s", s.constData(), object()->metaObject()->className()); qWarning("Signal %s unknown in %s", s.constData(), object()->metaObject()->className());
d->primarySignals << QLatin1String(s); d->primarySignals << QLatin1String(s);
} }

View File

@ -282,7 +282,7 @@ void QAccessibleTextEdit::scrollToSubstring(int startIndex, int endIndex)
r.y() + edit->verticalScrollBar()->value()); r.y() + edit->verticalScrollBar()->value());
// E V I L, but ensureVisible is not public // E V I L, but ensureVisible is not public
if (!QMetaObject::invokeMethod(edit, "_q_ensureVisible", Q_ARG(QRectF, r))) if (Q_UNLIKELY(!QMetaObject::invokeMethod(edit, "_q_ensureVisible", Q_ARG(QRectF, r))))
qWarning("AccessibleTextEdit::scrollToSubstring failed!"); qWarning("AccessibleTextEdit::scrollToSubstring failed!");
} }

View File

@ -316,8 +316,8 @@ QPixmap QGraphicsEffectSource::pixmap(Qt::CoordinateSystem system, QPoint *offse
return pixmapItem->pixmap(); return pixmapItem->pixmap();
} }
if (system == Qt::DeviceCoordinates && item if (Q_UNLIKELY(system == Qt::DeviceCoordinates && item &&
&& !static_cast<const QGraphicsItemEffectSourcePrivate *>(d_func())->info) { !static_cast<const QGraphicsItemEffectSourcePrivate *>(d_func())->info)) {
qWarning("QGraphicsEffectSource::pixmap: Not yet implemented, lacking device context"); qWarning("QGraphicsEffectSource::pixmap: Not yet implemented, lacking device context");
return QPixmap(); return QPixmap();
} }

View File

@ -758,7 +758,7 @@ void QAbstractItemView::setSelectionModel(QItemSelectionModel *selectionModel)
Q_ASSERT(selectionModel); Q_ASSERT(selectionModel);
Q_D(QAbstractItemView); Q_D(QAbstractItemView);
if (selectionModel->model() != d->model) { if (Q_UNLIKELY(selectionModel->model() != d->model)) {
qWarning("QAbstractItemView::setSelectionModel() failed: " qWarning("QAbstractItemView::setSelectionModel() failed: "
"Trying to set a selection model, which works on " "Trying to set a selection model, which works on "
"a different model than the view."); "a different model than the view.");
@ -1113,7 +1113,7 @@ void QAbstractItemView::reset()
void QAbstractItemView::setRootIndex(const QModelIndex &index) void QAbstractItemView::setRootIndex(const QModelIndex &index)
{ {
Q_D(QAbstractItemView); Q_D(QAbstractItemView);
if (index.isValid() && index.model() != d->model) { if (Q_UNLIKELY(index.isValid() && index.model() != d->model)) {
qWarning("QAbstractItemView::setRootIndex failed : index must be from the currently set model"); qWarning("QAbstractItemView::setRootIndex failed : index must be from the currently set model");
return; return;
} }
@ -1166,9 +1166,9 @@ void QAbstractItemView::selectAll()
void QAbstractItemView::edit(const QModelIndex &index) void QAbstractItemView::edit(const QModelIndex &index)
{ {
Q_D(QAbstractItemView); Q_D(QAbstractItemView);
if (!d->isIndexValid(index)) if (Q_UNLIKELY(!d->isIndexValid(index)))
qWarning("edit: index was invalid"); qWarning("edit: index was invalid");
if (!edit(index, AllEditTriggers, 0)) if (Q_UNLIKELY(!edit(index, AllEditTriggers, 0)))
qWarning("edit: editing failed"); qWarning("edit: editing failed");
} }

View File

@ -1022,7 +1022,7 @@ bool QDirModel::rmdir(const QModelIndex &index)
return false; return false;
QDirModelPrivate::QDirNode *n = d_func()->node(index); QDirModelPrivate::QDirNode *n = d_func()->node(index);
if (!n->info.isDir()) { if (Q_UNLIKELY(!n->info.isDir())) {
qWarning("rmdir: the node is not a directory"); qWarning("rmdir: the node is not a directory");
return false; return false;
} }
@ -1172,7 +1172,7 @@ QDirModelPrivate::QDirNode *QDirModelPrivate::node(int row, QDirNode *parent) co
if (isDir && !p->populated) if (isDir && !p->populated)
populate(p); // will also resolve symlinks populate(p); // will also resolve symlinks
if (row >= p->children.count()) { if (Q_UNLIKELY(row >= p->children.count())) {
qWarning("node: the row does not exist"); qWarning("node: the row does not exist");
return 0; return 0;
} }

View File

@ -392,7 +392,7 @@ int QListView::spacing() const
void QListView::setBatchSize(int batchSize) void QListView::setBatchSize(int batchSize)
{ {
Q_D(QListView); Q_D(QListView);
if (batchSize <= 0) { if (Q_UNLIKELY(batchSize <= 0)) {
qWarning("Invalid batchSize (%d)", batchSize); qWarning("Invalid batchSize (%d)", batchSize);
return; return;
} }

View File

@ -669,7 +669,7 @@ void QTableViewPrivate::trimHiddenSelections(QItemSelectionRange *range) const
*/ */
void QTableViewPrivate::setSpan(int row, int column, int rowSpan, int columnSpan) void QTableViewPrivate::setSpan(int row, int column, int rowSpan, int columnSpan)
{ {
if (row < 0 || column < 0 || rowSpan <= 0 || columnSpan <= 0) { if (Q_UNLIKELY(row < 0 || column < 0 || rowSpan <= 0 || columnSpan <= 0)) {
qWarning("QTableView::setSpan: invalid span given: (%d, %d, %d, %d)", qWarning("QTableView::setSpan: invalid span given: (%d, %d, %d, %d)",
row, column, rowSpan, columnSpan); row, column, rowSpan, columnSpan);
return; return;
@ -688,7 +688,7 @@ void QTableViewPrivate::setSpan(int row, int column, int rowSpan, int columnSpan
sp->m_right = column + columnSpan - 1; sp->m_right = column + columnSpan - 1;
spans.updateSpan(sp, old_height); spans.updateSpan(sp, old_height);
return; return;
} else if (rowSpan == 1 && columnSpan == 1) { } else if (Q_UNLIKELY(rowSpan == 1 && columnSpan == 1)) {
qWarning("QTableView::setSpan: single cell span won't be added"); qWarning("QTableView::setSpan: single cell span won't be added");
return; return;
} }

View File

@ -1958,7 +1958,7 @@ void QTableWidget::setItem(int row, int column, QTableWidgetItem *item)
{ {
Q_D(QTableWidget); Q_D(QTableWidget);
if (item) { if (item) {
if (item->view != 0) { if (Q_UNLIKELY(item->view)) {
qWarning("QTableWidget: cannot insert an item that is already owned by another QTableWidget"); qWarning("QTableWidget: cannot insert an item that is already owned by another QTableWidget");
} else { } else {
item->view = this; item->view = this;

View File

@ -3280,14 +3280,14 @@ QMimeData *QTreeWidget::mimeData(const QList<QTreeWidgetItem*> items) const
QList<QModelIndex> indexes; QList<QModelIndex> indexes;
for (int i = 0; i < items.count(); ++i) { for (int i = 0; i < items.count(); ++i) {
QTreeWidgetItem *item = items.at(i); QTreeWidgetItem *item = items.at(i);
if (!item) { if (Q_UNLIKELY(!item)) {
qWarning("QTreeWidget::mimeData: Null-item passed"); qWarning("QTreeWidget::mimeData: Null-item passed");
return 0; return 0;
} }
for (int c = 0; c < item->values.count(); ++c) { for (int c = 0; c < item->values.count(); ++c) {
const QModelIndex index = indexFromItem(item, c); const QModelIndex index = indexFromItem(item, c);
if (!index.isValid()) { if (Q_UNLIKELY(!index.isValid())) {
qWarning() << "QTreeWidget::mimeData: No index associated with item :" << item; qWarning() << "QTreeWidget::mimeData: No index associated with item :" << item;
return 0; return 0;
} }

View File

@ -45,7 +45,7 @@
#include <private/qmenu_p.h> #include <private/qmenu_p.h>
#define QAPP_CHECK(functionName) \ #define QAPP_CHECK(functionName) \
if (!qApp) { \ if (Q_UNLIKELY(!qApp)) { \
qWarning("QAction: Initialize QApplication before calling '" functionName "'."); \ qWarning("QAction: Initialize QApplication before calling '" functionName "'."); \
return; \ return; \
} }

View File

@ -1368,7 +1368,7 @@ int QApplication::colorSpec()
void QApplication::setColorSpec(int spec) void QApplication::setColorSpec(int spec)
{ {
if (qApp) if (Q_UNLIKELY(qApp))
qWarning("QApplication::setColorSpec: This function must be " qWarning("QApplication::setColorSpec: This function must be "
"called before the QApplication object is created"); "called before the QApplication object is created");
QApplicationPrivate::app_cspec = spec; QApplicationPrivate::app_cspec = spec;
@ -2485,7 +2485,7 @@ bool QApplicationPrivate::isBlockedByModal(QWidget *widget)
bool QApplicationPrivate::isWindowBlocked(QWindow *window, QWindow **blockingWindow) const bool QApplicationPrivate::isWindowBlocked(QWindow *window, QWindow **blockingWindow) const
{ {
QWindow *unused = 0; QWindow *unused = 0;
if (!window) { if (Q_UNLIKELY(!window)) {
qWarning().nospace() << "window == 0 passed."; qWarning().nospace() << "window == 0 passed.";
return false; return false;
} }
@ -3007,7 +3007,7 @@ bool QApplication::notify(QObject *receiver, QEvent *e)
if (QApplicationPrivate::is_app_closing) if (QApplicationPrivate::is_app_closing)
return true; return true;
if (receiver == 0) { // serious error if (Q_UNLIKELY(!receiver)) { // serious error
qWarning("QApplication::notify: Unexpected null receiver"); qWarning("QApplication::notify: Unexpected null receiver");
return true; return true;
} }
@ -3256,7 +3256,7 @@ bool QApplication::notify(QObject *receiver, QEvent *e)
QObject *obj = d->extraData->eventFilters.at(i); QObject *obj = d->extraData->eventFilters.at(i);
if (!obj) if (!obj)
continue; continue;
if (obj->d_func()->threadData != w->d_func()->threadData) { if (Q_UNLIKELY(obj->d_func()->threadData != w->d_func()->threadData)) {
qWarning("QApplication: Object event filter cannot be in a different thread."); qWarning("QApplication: Object event filter cannot be in a different thread.");
continue; continue;
} }

View File

@ -48,7 +48,7 @@ int QDesktopScreenWidget::screenNumber() const
const QRect QDesktopWidget::screenGeometry(const QWidget *widget) const const QRect QDesktopWidget::screenGeometry(const QWidget *widget) const
{ {
if (!widget) { if (Q_UNLIKELY(!widget)) {
qWarning("QDesktopWidget::screenGeometry(): Attempt " qWarning("QDesktopWidget::screenGeometry(): Attempt "
"to get the screen geometry of a null widget"); "to get the screen geometry of a null widget");
return QRect(); return QRect();
@ -61,7 +61,7 @@ const QRect QDesktopWidget::screenGeometry(const QWidget *widget) const
const QRect QDesktopWidget::availableGeometry(const QWidget *widget) const const QRect QDesktopWidget::availableGeometry(const QWidget *widget) const
{ {
if (!widget) { if (Q_UNLIKELY(!widget)) {
qWarning("QDesktopWidget::availableGeometry(): Attempt " qWarning("QDesktopWidget::availableGeometry(): Attempt "
"to get the available geometry of a null widget"); "to get the available geometry of a null widget");
return QRect(); return QRect();

View File

@ -945,7 +945,7 @@ void QFormLayoutPrivate::setItem(int row, QFormLayout::ItemRole role, QLayoutIte
{ {
const bool fullRow = role == QFormLayout::SpanningRole; const bool fullRow = role == QFormLayout::SpanningRole;
const int column = role == QFormLayout::SpanningRole ? 1 : static_cast<int>(role); const int column = role == QFormLayout::SpanningRole ? 1 : static_cast<int>(role);
if (uint(row) >= uint(m_matrix.rowCount()) || uint(column) > 1U) { if (Q_UNLIKELY(uint(row) >= uint(m_matrix.rowCount()) || uint(column) > 1U)) {
qWarning("QFormLayoutPrivate::setItem: Invalid cell (%d, %d)", row, column); qWarning("QFormLayoutPrivate::setItem: Invalid cell (%d, %d)", row, column);
return; return;
} }
@ -953,7 +953,7 @@ void QFormLayoutPrivate::setItem(int row, QFormLayout::ItemRole role, QLayoutIte
if (!item) if (!item)
return; return;
if (m_matrix(row, column)) { if (Q_UNLIKELY(m_matrix(row, column))) {
qWarning("QFormLayoutPrivate::setItem: Cell (%d, %d) already occupied", row, column); qWarning("QFormLayoutPrivate::setItem: Cell (%d, %d) already occupied", row, column);
return; return;
} }
@ -1000,7 +1000,7 @@ QLayoutItem* QFormLayoutPrivate::replaceAt(int index, QLayoutItem *newitem)
if (!newitem) if (!newitem)
return 0; return 0;
const int storageIndex = storageIndexFromLayoutItem(m_matrix, m_things.value(index)); const int storageIndex = storageIndexFromLayoutItem(m_matrix, m_things.value(index));
if (storageIndex == -1) { if (Q_UNLIKELY(storageIndex == -1)) {
// ### Qt6 - fix warning too when this class becomes public // ### Qt6 - fix warning too when this class becomes public
qWarning("QFormLayoutPrivate::replaceAt: Invalid index %d", index); qWarning("QFormLayoutPrivate::replaceAt: Invalid index %d", index);
return 0; return 0;
@ -1414,7 +1414,7 @@ QLayoutItem *QFormLayout::takeAt(int index)
Q_D(QFormLayout); Q_D(QFormLayout);
const int storageIndex = storageIndexFromLayoutItem(d->m_matrix, d->m_things.value(index)); const int storageIndex = storageIndexFromLayoutItem(d->m_matrix, d->m_things.value(index));
if (storageIndex == -1) { if (Q_UNLIKELY(storageIndex == -1)) {
qWarning("QFormLayout::takeAt: Invalid index %d", index); qWarning("QFormLayout::takeAt: Invalid index %d", index);
return 0; return 0;
} }

View File

@ -117,7 +117,7 @@ QGestureManager::~QGestureManager()
Qt::GestureType QGestureManager::registerGestureRecognizer(QGestureRecognizer *recognizer) Qt::GestureType QGestureManager::registerGestureRecognizer(QGestureRecognizer *recognizer)
{ {
QGesture *dummy = recognizer->create(0); QGesture *dummy = recognizer->create(0);
if (!dummy) { if (Q_UNLIKELY(!dummy)) {
qWarning("QGestureManager::registerGestureRecognizer: " qWarning("QGestureManager::registerGestureRecognizer: "
"the recognizer fails to create a gesture object, skipping registration."); "the recognizer fails to create a gesture object, skipping registration.");
return Qt::GestureType(0); return Qt::GestureType(0);
@ -640,17 +640,17 @@ void QGestureManager::deliverEvents(const QSet<QGesture *> &gestures,
Q_ASSERT(gestureType != Qt::CustomGesture); Q_ASSERT(gestureType != Qt::CustomGesture);
Q_UNUSED(gestureType); Q_UNUSED(gestureType);
if (target) { if (Q_UNLIKELY(!target)) {
qCDebug(lcGestureManager) << "QGestureManager::deliverEvent: could not find the target for gesture"
<< gesture->gestureType();
qWarning("QGestureManager::deliverEvent: could not find the target for gesture");
undeliveredGestures->insert(gesture);
} else {
if (gesture->state() == Qt::GestureStarted) { if (gesture->state() == Qt::GestureStarted) {
startedGestures.insert(gesture); startedGestures.insert(gesture);
} else { } else {
normalStartedGestures[target].append(gesture); normalStartedGestures[target].append(gesture);
} }
} else {
qCDebug(lcGestureManager) << "QGestureManager::deliverEvent: could not find the target for gesture"
<< gesture->gestureType();
qWarning("QGestureManager::deliverEvent: could not find the target for gesture");
undeliveredGestures->insert(gesture);
} }
} }

View File

@ -557,9 +557,9 @@ void QGridLayoutPrivate::add(QGridBox *box, int row, int col)
void QGridLayoutPrivate::add(QGridBox *box, int row1, int row2, int col1, int col2) void QGridLayoutPrivate::add(QGridBox *box, int row1, int row2, int col1, int col2)
{ {
if (row2 >= 0 && row2 < row1) if (Q_UNLIKELY(row2 >= 0 && row2 < row1))
qWarning("QGridLayout: Multi-cell fromRow greater than toRow"); qWarning("QGridLayout: Multi-cell fromRow greater than toRow");
if (col2 >= 0 && col2 < col1) if (Q_UNLIKELY(col2 >= 0 && col2 < col1))
qWarning("QGridLayout: Multi-cell fromCol greater than toCol"); qWarning("QGridLayout: Multi-cell fromCol greater than toCol");
if (row1 == row2 && col1 == col2) { if (row1 == row2 && col1 == col2) {
add(box, row1, col1); add(box, row1, col1);
@ -1435,7 +1435,7 @@ void QGridLayout::addWidget(QWidget *widget, int row, int column, Qt::Alignment
Q_D(QGridLayout); Q_D(QGridLayout);
if (!d->checkWidget(widget)) if (!d->checkWidget(widget))
return; return;
if (row < 0 || column < 0) { if (Q_UNLIKELY(row < 0 || column < 0)) {
qWarning("QGridLayout: Cannot add %s/%s to %s/%s at row %d column %d", qWarning("QGridLayout: Cannot add %s/%s to %s/%s at row %d column %d",
widget->metaObject()->className(), widget->objectName().toLocal8Bit().data(), widget->metaObject()->className(), widget->objectName().toLocal8Bit().data(),
metaObject()->className(), objectName().toLocal8Bit().data(), row, column); metaObject()->className(), objectName().toLocal8Bit().data(), row, column);

View File

@ -129,7 +129,7 @@ QLayout::QLayout(QLayoutPrivate &dd, QLayout *lay, QWidget *w)
if (lay) { if (lay) {
lay->addItem(this); lay->addItem(this);
} else if (w) { } else if (w) {
if (w->layout()) { if (Q_UNLIKELY(w->layout())) {
qWarning("QLayout: Attempting to add QLayout \"%ls\" to %s \"%ls\", which" qWarning("QLayout: Attempting to add QLayout \"%ls\" to %s \"%ls\", which"
" already has a layout", " already has a layout",
qUtf16Printable(QObject::objectName()), w->metaObject()->className(), qUtf16Printable(QObject::objectName()), w->metaObject()->className(),
@ -469,7 +469,7 @@ QWidget *QLayout::parentWidget() const
if (!d->topLevel) { if (!d->topLevel) {
if (parent()) { if (parent()) {
QLayout *parentLayout = qobject_cast<QLayout*>(parent()); QLayout *parentLayout = qobject_cast<QLayout*>(parent());
if (!parentLayout) { if (Q_UNLIKELY(!parentLayout)) {
qWarning("QLayout::parentWidget: A layout can only have another layout as a parent."); qWarning("QLayout::parentWidget: A layout can only have another layout as a parent.");
return 0; return 0;
} }
@ -776,7 +776,7 @@ QLayout::~QLayout()
*/ */
void QLayout::addChildLayout(QLayout *l) void QLayout::addChildLayout(QLayout *l)
{ {
if (l->parent()) { if (Q_UNLIKELY(l->parent())) {
qWarning("QLayout::addChildLayout: layout \"%ls\" already has a parent", qWarning("QLayout::addChildLayout: layout \"%ls\" already has a parent",
qUtf16Printable(l->objectName())); qUtf16Printable(l->objectName()));
return; return;
@ -826,7 +826,7 @@ void QLayoutPrivate::reparentChildWidgets(QWidget *mw)
if (QWidget *w = item->widget()) { if (QWidget *w = item->widget()) {
QWidget *pw = w->parentWidget(); QWidget *pw = w->parentWidget();
#ifdef QT_DEBUG #ifdef QT_DEBUG
if (pw && pw != mw && layoutDebug()) { if (Q_UNLIKELY(pw && pw != mw && layoutDebug())) {
qWarning("QLayout::addChildLayout: widget %s \"%ls\" in wrong parent; moved to correct parent", qWarning("QLayout::addChildLayout: widget %s \"%ls\" in wrong parent; moved to correct parent",
w->metaObject()->className(), qUtf16Printable(w->objectName())); w->metaObject()->className(), qUtf16Printable(w->objectName()));
} }
@ -849,12 +849,12 @@ void QLayoutPrivate::reparentChildWidgets(QWidget *mw)
bool QLayoutPrivate::checkWidget(QWidget *widget) const bool QLayoutPrivate::checkWidget(QWidget *widget) const
{ {
Q_Q(const QLayout); Q_Q(const QLayout);
if (!widget) { if (Q_UNLIKELY(!widget)) {
qWarning("QLayout: Cannot add a null widget to %s/%ls", q->metaObject()->className(), qWarning("QLayout: Cannot add a null widget to %s/%ls", q->metaObject()->className(),
qUtf16Printable(q->objectName())); qUtf16Printable(q->objectName()));
return false; return false;
} }
if (widget == q->parentWidget()) { if (Q_UNLIKELY(widget == q->parentWidget())) {
qWarning("QLayout: Cannot add parent widget %s/%ls to its child layout %s/%ls", qWarning("QLayout: Cannot add parent widget %s/%ls to its child layout %s/%ls",
widget->metaObject()->className(), qUtf16Printable(widget->objectName()), widget->metaObject()->className(), qUtf16Printable(widget->objectName()),
q->metaObject()->className(), qUtf16Printable(q->objectName())); q->metaObject()->className(), qUtf16Printable(q->objectName()));
@ -870,12 +870,12 @@ bool QLayoutPrivate::checkWidget(QWidget *widget) const
bool QLayoutPrivate::checkLayout(QLayout *otherLayout) const bool QLayoutPrivate::checkLayout(QLayout *otherLayout) const
{ {
Q_Q(const QLayout); Q_Q(const QLayout);
if (!otherLayout) { if (Q_UNLIKELY(!otherLayout)) {
qWarning("QLayout: Cannot add a null layout to %s/%ls", qWarning("QLayout: Cannot add a null layout to %s/%ls",
q->metaObject()->className(), qUtf16Printable(q->objectName())); q->metaObject()->className(), qUtf16Printable(q->objectName()));
return false; return false;
} }
if (otherLayout == q) { if (Q_UNLIKELY(otherLayout == q)) {
qWarning("QLayout: Cannot add layout %s/%ls to itself", qWarning("QLayout: Cannot add layout %s/%ls to itself",
q->metaObject()->className(), qUtf16Printable(q->objectName())); q->metaObject()->className(), qUtf16Printable(q->objectName()));
return false; return false;
@ -902,7 +902,7 @@ void QLayout::addChildWidget(QWidget *w)
QLayout *l = pw->layout(); QLayout *l = pw->layout();
if (l && removeWidgetRecursively(l, w)) { if (l && removeWidgetRecursively(l, w)) {
#ifdef QT_DEBUG #ifdef QT_DEBUG
if (layoutDebug()) if (Q_UNLIKELY(layoutDebug()))
qWarning("QLayout::addChildWidget: %s \"%ls\" is already in a layout; moved to new layout", qWarning("QLayout::addChildWidget: %s \"%ls\" is already in a layout; moved to new layout",
w->metaObject()->className(), qUtf16Printable(w->objectName())); w->metaObject()->className(), qUtf16Printable(w->objectName()));
#endif #endif
@ -910,7 +910,7 @@ void QLayout::addChildWidget(QWidget *w)
} }
if (pw && mw && pw != mw) { if (pw && mw && pw != mw) {
#ifdef QT_DEBUG #ifdef QT_DEBUG
if (layoutDebug()) if (Q_UNLIKELY(layoutDebug()))
qWarning("QLayout::addChildWidget: %s \"%ls\" in wrong parent; moved to correct parent", qWarning("QLayout::addChildWidget: %s \"%ls\" in wrong parent; moved to correct parent",
w->metaObject()->className(), qUtf16Printable(w->objectName())); w->metaObject()->className(), qUtf16Printable(w->objectName()));
#endif #endif
@ -1064,7 +1064,7 @@ bool QLayout::activate()
if (d->activated) if (d->activated)
return false; return false;
QWidget *mw = static_cast<QWidget*>(parent()); QWidget *mw = static_cast<QWidget*>(parent());
if (mw == 0) { if (Q_UNLIKELY(!mw)) {
qWarning("QLayout::activate: %s \"%ls\" does not have a main widget", qWarning("QLayout::activate: %s \"%ls\" does not have a main widget",
metaObject()->className(), qUtf16Printable(objectName())); metaObject()->className(), qUtf16Printable(objectName()));
return false; return false;

View File

@ -740,7 +740,7 @@ void QOpenGLWidgetPrivate::initialize()
// texture usable by the underlying window's backingstore. // texture usable by the underlying window's backingstore.
QWidget *tlw = q->window(); QWidget *tlw = q->window();
QOpenGLContext *shareContext = get(tlw)->shareContext(); QOpenGLContext *shareContext = get(tlw)->shareContext();
if (!shareContext) { if (Q_UNLIKELY(!shareContext)) {
qWarning("QOpenGLWidget: Cannot be used without a context shared with the toplevel."); qWarning("QOpenGLWidget: Cannot be used without a context shared with the toplevel.");
return; return;
} }
@ -756,7 +756,7 @@ void QOpenGLWidgetPrivate::initialize()
ctx->setShareContext(shareContext); ctx->setShareContext(shareContext);
ctx->setFormat(requestedFormat); ctx->setFormat(requestedFormat);
ctx->setScreen(shareContext->screen()); ctx->setScreen(shareContext->screen());
if (!ctx->create()) { if (Q_UNLIKELY(!ctx->create())) {
qWarning("QOpenGLWidget: Failed to create context"); qWarning("QOpenGLWidget: Failed to create context");
return; return;
} }
@ -782,7 +782,7 @@ void QOpenGLWidgetPrivate::initialize()
surface->setScreen(ctx->screen()); surface->setScreen(ctx->screen());
surface->create(); surface->create();
if (!ctx->makeCurrent(surface)) { if (Q_UNLIKELY(!ctx->makeCurrent(surface))) {
qWarning("QOpenGLWidget: Failed to make context current"); qWarning("QOpenGLWidget: Failed to make context current");
return; return;
} }
@ -915,10 +915,10 @@ QOpenGLWidget::QOpenGLWidget(QWidget *parent, Qt::WindowFlags f)
: QWidget(*(new QOpenGLWidgetPrivate), parent, f) : QWidget(*(new QOpenGLWidgetPrivate), parent, f)
{ {
Q_D(QOpenGLWidget); Q_D(QOpenGLWidget);
if (QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::RasterGLSurface)) if (Q_UNLIKELY(!QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::RasterGLSurface)))
d->setRenderToTexture();
else
qWarning("QOpenGLWidget is not supported on this platform."); qWarning("QOpenGLWidget is not supported on this platform.");
else
d->setRenderToTexture();
} }
/*! /*!
@ -984,7 +984,7 @@ void QOpenGLWidget::setFormat(const QSurfaceFormat &format)
{ {
Q_UNUSED(format); Q_UNUSED(format);
Q_D(QOpenGLWidget); Q_D(QOpenGLWidget);
if (d->initialized) { if (Q_UNLIKELY(d->initialized)) {
qWarning("QOpenGLWidget: Already initialized, setting the format has no effect"); qWarning("QOpenGLWidget: Already initialized, setting the format has no effect");
return; return;
} }

View File

@ -49,7 +49,7 @@
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
#define QAPP_CHECK(functionName) \ #define QAPP_CHECK(functionName) \
if (!qApp) { \ if (Q_UNLIKELY(!qApp)) { \
qWarning("QShortcut: Initialize QApplication before calling '" functionName "'."); \ qWarning("QShortcut: Initialize QApplication before calling '" functionName "'."); \
return; \ return; \
} }
@ -410,7 +410,7 @@ public:
void QShortcutPrivate::redoGrab(QShortcutMap &map) void QShortcutPrivate::redoGrab(QShortcutMap &map)
{ {
Q_Q(QShortcut); Q_Q(QShortcut);
if (!parent) { if (Q_UNLIKELY(!parent)) {
qWarning("QShortcut: No widget parent defined"); qWarning("QShortcut: No widget parent defined");
return; return;
} }

View File

@ -57,7 +57,7 @@ QLayoutItem* QStackedLayoutPrivate::replaceAt(int idx, QLayoutItem *newitem)
if (idx < 0 || idx >= list.size() || !newitem) if (idx < 0 || idx >= list.size() || !newitem)
return 0; return 0;
QWidget *wdg = newitem->widget(); QWidget *wdg = newitem->widget();
if (!wdg) { if (Q_UNLIKELY(!wdg)) {
qWarning("QStackedLayout::replaceAt: Only widgets can be added"); qWarning("QStackedLayout::replaceAt: Only widgets can be added");
return 0; return 0;
} }
@ -367,7 +367,7 @@ int QStackedLayout::currentIndex() const
void QStackedLayout::setCurrentWidget(QWidget *widget) void QStackedLayout::setCurrentWidget(QWidget *widget)
{ {
int index = indexOf(widget); int index = indexOf(widget);
if (index == -1) { if (Q_UNLIKELY(index == -1)) {
qWarning("QStackedLayout::setCurrentWidget: Widget %p not contained in stack", widget); qWarning("QStackedLayout::setCurrentWidget: Widget %p not contained in stack", widget);
return; return;
} }
@ -420,12 +420,12 @@ int QStackedLayout::count() const
void QStackedLayout::addItem(QLayoutItem *item) void QStackedLayout::addItem(QLayoutItem *item)
{ {
QWidget *widget = item->widget(); QWidget *widget = item->widget();
if (widget) { if (Q_UNLIKELY(!widget)) {
addWidget(widget);
delete item;
} else {
qWarning("QStackedLayout::addItem: Only widgets can be added"); qWarning("QStackedLayout::addItem: Only widgets can be added");
return;
} }
addWidget(widget);
delete item;
} }
/*! /*!

View File

@ -264,12 +264,12 @@ void QTipLabel::hideTipImmediately()
void QTipLabel::setTipRect(QWidget *w, const QRect &r) void QTipLabel::setTipRect(QWidget *w, const QRect &r)
{ {
if (!r.isNull() && !w) if (Q_UNLIKELY(!r.isNull() && !w)) {
qWarning("QToolTip::setTipRect: Cannot pass null widget if rect is set"); qWarning("QToolTip::setTipRect: Cannot pass null widget if rect is set");
else{ return;
widget = w;
rect = r;
} }
widget = w;
rect = r;
} }
void QTipLabel::timerEvent(QTimerEvent *e) void QTipLabel::timerEvent(QTimerEvent *e)

View File

@ -1528,7 +1528,7 @@ QWidget::~QWidget()
d->data.in_destructor = true; d->data.in_destructor = true;
#if defined (QT_CHECK_STATE) #if defined (QT_CHECK_STATE)
if (paintingActive()) if (Q_UNLIKELY(paintingActive()))
qWarning("QWidget: %s (%s) deleted while being painted", className(), name()); qWarning("QWidget: %s (%s) deleted while being painted", className(), name());
#endif #endif
@ -3267,7 +3267,7 @@ void QWidget::addActions(QList<QAction*> actions)
*/ */
void QWidget::insertAction(QAction *before, QAction *action) void QWidget::insertAction(QAction *before, QAction *action)
{ {
if(!action) { if (Q_UNLIKELY(!action)) {
qWarning("QWidget::insertAction: Attempt to insert null action"); qWarning("QWidget::insertAction: Attempt to insert null action");
return; return;
} }
@ -3913,7 +3913,7 @@ bool QWidgetPrivate::setMinimumSize_helper(int &minw, int &minh)
mw = 0; mw = 0;
if (mh == QWIDGETSIZE_MAX) if (mh == QWIDGETSIZE_MAX)
mh = 0; mh = 0;
if (minw > QWIDGETSIZE_MAX || minh > QWIDGETSIZE_MAX) { if (Q_UNLIKELY(minw > QWIDGETSIZE_MAX || minh > QWIDGETSIZE_MAX)) {
qWarning("QWidget::setMinimumSize: (%s/%s) " qWarning("QWidget::setMinimumSize: (%s/%s) "
"The largest allowed size is (%d,%d)", "The largest allowed size is (%d,%d)",
q->objectName().toLocal8Bit().data(), q->metaObject()->className(), QWIDGETSIZE_MAX, q->objectName().toLocal8Bit().data(), q->metaObject()->className(), QWIDGETSIZE_MAX,
@ -3921,7 +3921,7 @@ bool QWidgetPrivate::setMinimumSize_helper(int &minw, int &minh)
minw = mw = qMin<int>(minw, QWIDGETSIZE_MAX); minw = mw = qMin<int>(minw, QWIDGETSIZE_MAX);
minh = mh = qMin<int>(minh, QWIDGETSIZE_MAX); minh = mh = qMin<int>(minh, QWIDGETSIZE_MAX);
} }
if (minw < 0 || minh < 0) { if (Q_UNLIKELY(minw < 0 || minh < 0)) {
qWarning("QWidget::setMinimumSize: (%s/%s) Negative sizes (%d,%d) " qWarning("QWidget::setMinimumSize: (%s/%s) Negative sizes (%d,%d) "
"are not possible", "are not possible",
q->objectName().toLocal8Bit().data(), q->metaObject()->className(), minw, minh); q->objectName().toLocal8Bit().data(), q->metaObject()->className(), minw, minh);
@ -3995,7 +3995,7 @@ void QWidget::setMinimumSize(int minw, int minh)
bool QWidgetPrivate::setMaximumSize_helper(int &maxw, int &maxh) bool QWidgetPrivate::setMaximumSize_helper(int &maxw, int &maxh)
{ {
Q_Q(QWidget); Q_Q(QWidget);
if (maxw > QWIDGETSIZE_MAX || maxh > QWIDGETSIZE_MAX) { if (Q_UNLIKELY(maxw > QWIDGETSIZE_MAX || maxh > QWIDGETSIZE_MAX)) {
qWarning("QWidget::setMaximumSize: (%s/%s) " qWarning("QWidget::setMaximumSize: (%s/%s) "
"The largest allowed size is (%d,%d)", "The largest allowed size is (%d,%d)",
q->objectName().toLocal8Bit().data(), q->metaObject()->className(), QWIDGETSIZE_MAX, q->objectName().toLocal8Bit().data(), q->metaObject()->className(), QWIDGETSIZE_MAX,
@ -4003,7 +4003,7 @@ bool QWidgetPrivate::setMaximumSize_helper(int &maxw, int &maxh)
maxw = qMin<int>(maxw, QWIDGETSIZE_MAX); maxw = qMin<int>(maxw, QWIDGETSIZE_MAX);
maxh = qMin<int>(maxh, QWIDGETSIZE_MAX); maxh = qMin<int>(maxh, QWIDGETSIZE_MAX);
} }
if (maxw < 0 || maxh < 0) { if (Q_UNLIKELY(maxw < 0 || maxh < 0)) {
qWarning("QWidget::setMaximumSize: (%s/%s) Negative sizes (%d,%d) " qWarning("QWidget::setMaximumSize: (%s/%s) Negative sizes (%d,%d) "
"are not possible", "are not possible",
q->objectName().toLocal8Bit().data(), q->metaObject()->className(), maxw, maxh); q->objectName().toLocal8Bit().data(), q->metaObject()->className(), maxw, maxh);
@ -5104,12 +5104,12 @@ void QWidget::render(QPaintDevice *target, const QPoint &targetOffset,
void QWidget::render(QPainter *painter, const QPoint &targetOffset, void QWidget::render(QPainter *painter, const QPoint &targetOffset,
const QRegion &sourceRegion, RenderFlags renderFlags) const QRegion &sourceRegion, RenderFlags renderFlags)
{ {
if (!painter) { if (Q_UNLIKELY(!painter)) {
qWarning("QWidget::render: Null pointer to painter"); qWarning("QWidget::render: Null pointer to painter");
return; return;
} }
if (!painter->isActive()) { if (Q_UNLIKELY(!painter->isActive())) {
qWarning("QWidget::render: Cannot render with an inactive painter"); qWarning("QWidget::render: Cannot render with an inactive painter");
return; return;
} }
@ -5498,7 +5498,7 @@ void QWidgetPrivate::drawWidget(QPaintDevice *pdev, const QRegion &rgn, const QP
if (!toBePainted.isEmpty()) { if (!toBePainted.isEmpty()) {
if (!onScreen || alsoOnScreen) { if (!onScreen || alsoOnScreen) {
//update the "in paint event" flag //update the "in paint event" flag
if (q->testAttribute(Qt::WA_WState_InPaintEvent)) if (Q_UNLIKELY(q->testAttribute(Qt::WA_WState_InPaintEvent)))
qWarning("QWidget::repaint: Recursive repaint detected"); qWarning("QWidget::repaint: Recursive repaint detected");
q->setAttribute(Qt::WA_WState_InPaintEvent); q->setAttribute(Qt::WA_WState_InPaintEvent);
@ -5605,7 +5605,7 @@ void QWidgetPrivate::drawWidget(QPaintDevice *pdev, const QRegion &rgn, const QP
setSystemClip(pdev, QRegion()); setSystemClip(pdev, QRegion());
} }
q->setAttribute(Qt::WA_WState_InPaintEvent, false); q->setAttribute(Qt::WA_WState_InPaintEvent, false);
if (q->paintingActive()) if (Q_UNLIKELY(q->paintingActive()))
qWarning("QWidget::repaint: It is dangerous to leave painters active on a widget outside of the PaintEvent"); qWarning("QWidget::repaint: It is dangerous to leave painters active on a widget outside of the PaintEvent");
if (paintEngine && paintEngine->autoDestruct()) { if (paintEngine && paintEngine->autoDestruct()) {
@ -5654,7 +5654,7 @@ void QWidgetPrivate::sendPaintEvent(const QRegion &toBePainted)
void QWidgetPrivate::render(QPaintDevice *target, const QPoint &targetOffset, void QWidgetPrivate::render(QPaintDevice *target, const QPoint &targetOffset,
const QRegion &sourceRegion, QWidget::RenderFlags renderFlags) const QRegion &sourceRegion, QWidget::RenderFlags renderFlags)
{ {
if (!target) { if (Q_UNLIKELY(!target)) {
qWarning("QWidget::render: null pointer to paint device"); qWarning("QWidget::render: null pointer to paint device");
return; return;
} }
@ -5788,7 +5788,7 @@ QRectF QWidgetEffectSourcePrivate::boundingRect(Qt::CoordinateSystem system) con
if (system != Qt::DeviceCoordinates) if (system != Qt::DeviceCoordinates)
return m_widget->rect(); return m_widget->rect();
if (!context) { if (Q_UNLIKELY(!context)) {
// Device coordinates without context not yet supported. // Device coordinates without context not yet supported.
qWarning("QGraphicsEffectSource::boundingRect: Not yet implemented, lacking device context"); qWarning("QGraphicsEffectSource::boundingRect: Not yet implemented, lacking device context");
return QRectF(); return QRectF();
@ -5820,7 +5820,7 @@ QPixmap QWidgetEffectSourcePrivate::pixmap(Qt::CoordinateSystem system, QPoint *
QGraphicsEffect::PixmapPadMode mode) const QGraphicsEffect::PixmapPadMode mode) const
{ {
const bool deviceCoordinates = (system == Qt::DeviceCoordinates); const bool deviceCoordinates = (system == Qt::DeviceCoordinates);
if (!context && deviceCoordinates) { if (Q_UNLIKELY(!context && deviceCoordinates)) {
// Device coordinates without context not yet supported. // Device coordinates without context not yet supported.
qWarning("QGraphicsEffectSource::pixmap: Not yet implemented, lacking device context"); qWarning("QGraphicsEffectSource::pixmap: Not yet implemented, lacking device context");
return QPixmap(); return QPixmap();
@ -6353,7 +6353,7 @@ void QWidget::setFocusProxy(QWidget * w)
return; return;
for (QWidget* fp = w; fp; fp = fp->focusProxy()) { for (QWidget* fp = w; fp; fp = fp->focusProxy()) {
if (fp == this) { if (Q_UNLIKELY(fp == this)) {
qWarning("QWidget: %s (%s) already in focus proxy chain", metaObject()->className(), objectName().toLocal8Bit().constData()); qWarning("QWidget: %s (%s) already in focus proxy chain", metaObject()->className(), objectName().toLocal8Bit().constData());
return; return;
} }
@ -6867,7 +6867,7 @@ void QWidget::setTabOrder(QWidget* first, QWidget *second)
if (!first || !second || first->focusPolicy() == Qt::NoFocus || second->focusPolicy() == Qt::NoFocus) if (!first || !second || first->focusPolicy() == Qt::NoFocus || second->focusPolicy() == Qt::NoFocus)
return; return;
if (first->window() != second->window()) { if (Q_UNLIKELY(first->window() != second->window())) {
qWarning("QWidget::setTabOrder: 'first' and 'second' must be in the same window"); qWarning("QWidget::setTabOrder: 'first' and 'second' must be in the same window");
return; return;
} }
@ -10024,12 +10024,12 @@ QLayout *QWidget::layout() const
void QWidget::setLayout(QLayout *l) void QWidget::setLayout(QLayout *l)
{ {
if (!l) { if (Q_UNLIKELY(!l)) {
qWarning("QWidget::setLayout: Cannot set layout to 0"); qWarning("QWidget::setLayout: Cannot set layout to 0");
return; return;
} }
if (layout()) { if (layout()) {
if (layout() != l) if (Q_UNLIKELY(layout() != l))
qWarning("QWidget::setLayout: Attempting to set QLayout \"%s\" on %s \"%s\", which already has a" qWarning("QWidget::setLayout: Attempting to set QLayout \"%s\" on %s \"%s\", which already has a"
" layout", l->objectName().toLocal8Bit().data(), metaObject()->className(), " layout", l->objectName().toLocal8Bit().data(), metaObject()->className(),
objectName().toLocal8Bit().data()); objectName().toLocal8Bit().data());
@ -11374,7 +11374,7 @@ void QWidgetPrivate::setWindowModified_helper()
return; return;
bool on = q->testAttribute(Qt::WA_WindowModified); bool on = q->testAttribute(Qt::WA_WindowModified);
if (!platformWindow->setWindowModified(on)) { if (!platformWindow->setWindowModified(on)) {
if (!q->windowTitle().contains(QLatin1String("[*]")) && on) if (Q_UNLIKELY(on && !q->windowTitle().contains(QLatin1String("[*]"))))
qWarning("QWidget::setWindowModified: The window title does not contain a '[*]' placeholder"); qWarning("QWidget::setWindowModified: The window title does not contain a '[*]' placeholder");
setWindowTitle_helper(q->windowTitle()); setWindowTitle_helper(q->windowTitle());
setWindowIconText_helper(q->windowIconText()); setWindowIconText_helper(q->windowIconText());
@ -12124,7 +12124,7 @@ QOpenGLContext *QWidgetPrivate::shareContext() const
#ifdef QT_NO_OPENGL #ifdef QT_NO_OPENGL
return 0; return 0;
#else #else
if (!extra || !extra->topextra || !extra->topextra->window) { if (Q_UNLIKELY(!extra || !extra->topextra || !extra->topextra->window)) {
qWarning("Asking for share context for widget that does not have a window handle"); qWarning("Asking for share context for widget that does not have a window handle");
return 0; return 0;
} }

View File

@ -1554,7 +1554,7 @@ void QWidgetPrivate::repaint_sys(const QRegion &rgn)
QWidgetBackingStore::unflushPaint(q, toBePainted); QWidgetBackingStore::unflushPaint(q, toBePainted);
#endif #endif
if (q->paintingActive()) if (Q_UNLIKELY(q->paintingActive()))
qWarning("QWidget::repaint: It is dangerous to leave painters active on a widget outside of the PaintEvent"); qWarning("QWidget::repaint: It is dangerous to leave painters active on a widget outside of the PaintEvent");
} }

View File

@ -798,7 +798,7 @@ void QWidgetWindow::handleDragLeaveEvent(QDragLeaveEvent *event)
void QWidgetWindow::handleDropEvent(QDropEvent *event) void QWidgetWindow::handleDropEvent(QDropEvent *event)
{ {
if (m_dragTarget.isNull()) { if (Q_UNLIKELY(m_dragTarget.isNull())) {
qWarning() << Q_FUNC_INFO << m_widget << ": No drag target set."; qWarning() << Q_FUNC_INFO << m_widget << ": No drag target set.";
event->ignore(); event->ignore();
return; return;

View File

@ -193,7 +193,7 @@ QWindowContainer::QWindowContainer(QWindow *embeddedWindow, QWidget *parent, Qt:
: QWidget(*new QWindowContainerPrivate, parent, flags) : QWidget(*new QWindowContainerPrivate, parent, flags)
{ {
Q_D(QWindowContainer); Q_D(QWindowContainer);
if (!embeddedWindow) { if (Q_UNLIKELY(!embeddedWindow)) {
qWarning("QWindowContainer: embedded window cannot be null"); qWarning("QWindowContainer: embedded window cannot be null");
return; return;
} }

View File

@ -84,7 +84,7 @@ QAndroidStyle::QAndroidStyle()
++objectIterator) { ++objectIterator) {
QString key = objectIterator.key(); QString key = objectIterator.key();
QJsonValue value = objectIterator.value(); QJsonValue value = objectIterator.value();
if (!value.isObject()) { if (Q_UNLIKELY(!value.isObject())) {
qWarning("Style.json structure is unrecognized."); qWarning("Style.json structure is unrecognized.");
continue; continue;
} }

View File

@ -87,7 +87,7 @@ void qDrawShadeLine(QPainter *p, int x1, int y1, int x2, int y2,
const QPalette &pal, bool sunken, const QPalette &pal, bool sunken,
int lineWidth, int midLineWidth) int lineWidth, int midLineWidth)
{ {
if (!(p && lineWidth >= 0 && midLineWidth >= 0)) { if (Q_UNLIKELY(!p || lineWidth < 0 || midLineWidth < 0)) {
qWarning("qDrawShadeLine: Invalid parameters"); qWarning("qDrawShadeLine: Invalid parameters");
return; return;
} }
@ -203,7 +203,7 @@ void qDrawShadeRect(QPainter *p, int x, int y, int w, int h,
{ {
if (w == 0 || h == 0) if (w == 0 || h == 0)
return; return;
if (! (w > 0 && h > 0 && lineWidth >= 0 && midLineWidth >= 0)) { if (Q_UNLIKELY(w < 0 || h < 0 || lineWidth < 0 || midLineWidth < 0)) {
qWarning("qDrawShadeRect: Invalid parameters"); qWarning("qDrawShadeRect: Invalid parameters");
return; return;
} }
@ -303,7 +303,7 @@ void qDrawShadePanel(QPainter *p, int x, int y, int w, int h,
{ {
if (w == 0 || h == 0) if (w == 0 || h == 0)
return; return;
if (!(w > 0 && h > 0 && lineWidth >= 0)) { if (Q_UNLIKELY(w < 0 || h < 0 || lineWidth < 0)) {
qWarning("qDrawShadePanel: Invalid parameters"); qWarning("qDrawShadePanel: Invalid parameters");
} }
QColor shade = pal.dark().color(); QColor shade = pal.dark().color();
@ -509,7 +509,7 @@ void qDrawPlainRect(QPainter *p, int x, int y, int w, int h, const QColor &c,
{ {
if (w == 0 || h == 0) if (w == 0 || h == 0)
return; return;
if (!(w > 0 && h > 0 && lineWidth >= 0)) { if (Q_UNLIKELY(w < 0 || h < 0 || lineWidth < 0)) {
qWarning("qDrawPlainRect: Invalid parameters"); qWarning("qDrawPlainRect: Invalid parameters");
} }
QPen oldPen = p->pen(); QPen oldPen = p->pen();

View File

@ -1547,7 +1547,7 @@ QVector<QCss::StyleRule> QStyleSheetStyle::styleRules(const QObject *obj) const
if (ss.startsWith(QLatin1String("file:///"))) if (ss.startsWith(QLatin1String("file:///")))
ss.remove(0, 8); ss.remove(0, 8);
parser.init(ss, qApp->styleSheet() != ss); parser.init(ss, qApp->styleSheet() != ss);
if (!parser.parse(&appSs)) if (Q_UNLIKELY(!parser.parse(&appSs)))
qWarning("Could not parse application stylesheet"); qWarning("Could not parse application stylesheet");
appSs.origin = StyleSheetOrigin_Inline; appSs.origin = StyleSheetOrigin_Inline;
appSs.depth = 1; appSs.depth = 1;
@ -1569,7 +1569,7 @@ QVector<QCss::StyleRule> QStyleSheetStyle::styleRules(const QObject *obj) const
parser.init(styleSheet); parser.init(styleSheet);
if (!parser.parse(&ss)) { if (!parser.parse(&ss)) {
parser.init(QLatin1String("* {") + styleSheet + QLatin1Char('}')); parser.init(QLatin1String("* {") + styleSheet + QLatin1Char('}'));
if (!parser.parse(&ss)) if (Q_UNLIKELY(!parser.parse(&ss)))
qWarning("Could not parse stylesheet of object %p", o); qWarning("Could not parse stylesheet of object %p", o);
} }
ss.origin = StyleSheetOrigin_Inline; ss.origin = StyleSheetOrigin_Inline;
@ -2515,12 +2515,12 @@ void QStyleSheetStyle::setProperties(QWidget *w)
const QMetaObject *metaObject = w->metaObject(); const QMetaObject *metaObject = w->metaObject();
int index = metaObject->indexOfProperty(property.toLatin1()); int index = metaObject->indexOfProperty(property.toLatin1());
if (index == -1) { if (Q_UNLIKELY(index == -1)) {
qWarning() << w << " does not have a property named " << property; qWarning() << w << " does not have a property named " << property;
continue; continue;
} }
const QMetaProperty metaProperty = metaObject->property(index); const QMetaProperty metaProperty = metaObject->property(index);
if (!metaProperty.isWritable() || !metaProperty.isDesignable()) { if (Q_UNLIKELY(!metaProperty.isWritable() || !metaProperty.isDesignable())) {
qWarning() << w << " cannot design property named " << property; qWarning() << w << " cannot design property named " << property;
continue; continue;
} }

View File

@ -2471,12 +2471,12 @@ bool QWindowsVistaStylePrivate::initTreeViewTheming()
return true; return true;
m_treeViewHelper = createTreeViewHelperWindow(); m_treeViewHelper = createTreeViewHelperWindow();
if (!m_treeViewHelper) { if (Q_UNLIKELY(!m_treeViewHelper)) {
qWarning("%s: Unable to create the treeview helper window.", Q_FUNC_INFO); qWarning("%s: Unable to create the treeview helper window.", Q_FUNC_INFO);
return false; return false;
} }
const HRESULT hr = QWindowsXPStylePrivate::pSetWindowTheme(m_treeViewHelper, L"explorer", NULL); const HRESULT hr = QWindowsXPStylePrivate::pSetWindowTheme(m_treeViewHelper, L"explorer", NULL);
if (hr != S_OK) { if (Q_UNLIKELY(hr != S_OK)) {
qErrnoWarning("%s: SetWindowTheme() failed.", Q_FUNC_INFO); qErrnoWarning("%s: SetWindowTheme() failed.", Q_FUNC_INFO);
return false; return false;
} }

View File

@ -337,14 +337,14 @@ void QWindowsXPStylePrivate::cleanupHandleMap()
HTHEME QWindowsXPStylePrivate::createTheme(int theme, HWND hwnd) HTHEME QWindowsXPStylePrivate::createTheme(int theme, HWND hwnd)
{ {
if (theme < 0 || theme >= NThemes || !hwnd) { if (Q_UNLIKELY(theme < 0 || theme >= NThemes || !hwnd)) {
qWarning("%s: Invalid parameters #%d, %p", Q_FUNC_INFO, theme, hwnd); qWarning("%s: Invalid parameters #%d, %p", Q_FUNC_INFO, theme, hwnd);
return 0; return 0;
} }
if (!m_themes[theme]) { if (!m_themes[theme]) {
const wchar_t *name = themeNames[theme]; const wchar_t *name = themeNames[theme];
m_themes[theme] = pOpenThemeData(hwnd, name); m_themes[theme] = pOpenThemeData(hwnd, name);
if (!m_themes[theme]) if (Q_UNLIKELY(!m_themes[theme]))
qErrnoWarning("%s: OpenThemeData() failed for theme %d (%s).", qErrnoWarning("%s: OpenThemeData() failed for theme %d (%s).",
Q_FUNC_INFO, theme, qPrintable(themeName(theme))); Q_FUNC_INFO, theme, qPrintable(themeName(theme)));
} }
@ -504,13 +504,13 @@ HBITMAP QWindowsXPStylePrivate::buffer(int w, int h)
GdiFlush(); GdiFlush();
nullBitmap = (HBITMAP)SelectObject(bufferDC, bufferBitmap); nullBitmap = (HBITMAP)SelectObject(bufferDC, bufferBitmap);
if (!bufferBitmap) { if (Q_UNLIKELY(!bufferBitmap)) {
qErrnoWarning("QWindowsXPStylePrivate::buffer(%dx%d), CreateDIBSection() failed.", w, h); qErrnoWarning("QWindowsXPStylePrivate::buffer(%dx%d), CreateDIBSection() failed.", w, h);
bufferW = 0; bufferW = 0;
bufferH = 0; bufferH = 0;
return 0; return 0;
} }
if (!bufferPixels) { if (Q_UNLIKELY(!bufferPixels)) {
qErrnoWarning("QWindowsXPStylePrivate::buffer(%dx%d), CreateDIBSection() did not allocate pixel data.", w, h); qErrnoWarning("QWindowsXPStylePrivate::buffer(%dx%d), CreateDIBSection() did not allocate pixel data.", w, h);
bufferW = 0; bufferW = 0;
bufferH = 0; bufferH = 0;