QtWidgets: use printf-style qWarning/qDebug where possible (I)

The printf-style version of QDebug expands to a lot less code than the
std::ostream-style version. Of course, you pay in type safety (but
compilers warn about it these days), you cannot stream complex Qt
types and streaming QStrings is awkward, but in many cases you
actually improve on readability.

But the main reason is that something that's not supposed to be
executed under normal operation has no business bloating executable
code size.

This is not an attempt at converting all qWarnings() to printf-style,
only the low-hanging fruit.

In this first part, replace
   qWarning() << "...";
with
   qWarning("...");

Change-Id: I1f6869b024103c98262f1deae014e0d7337a541c
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@theqtcompany.com>
Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
This commit is contained in:
Marc Mutz 2015-10-17 17:48:34 +02:00
parent f8eeabcf5c
commit 29a7f5571c
16 changed files with 37 additions and 36 deletions

View File

@ -977,7 +977,7 @@ void QFileDialog::setDirectoryUrl(const QUrl &directory)
else if (directory.isLocalFile())
setDirectory(directory.toLocalFile());
else if (d->usingWidgets())
qWarning() << "Non-native QFileDialog supports only local files";
qWarning("Non-native QFileDialog supports only local files");
}
/*!
@ -1087,7 +1087,7 @@ void QFileDialog::selectUrl(const QUrl &url)
else if (url.isLocalFile())
selectFile(url.toLocalFile());
else
qWarning() << "Non-native QFileDialog supports only local files";
qWarning("Non-native QFileDialog supports only local files");
}
#ifdef Q_OS_UNIX

View File

@ -473,7 +473,7 @@ void QFileSystemModel::timerEvent(QTimerEvent *event)
d->fileInfoGatherer.fetchExtendedInformation(d->toFetch.at(i).dir,
QStringList(d->toFetch.at(i).file));
} else {
// qDebug() << "yah!, you saved a little gerbil soul";
// qDebug("yah!, you saved a little gerbil soul");
}
}
#endif

View File

@ -116,7 +116,7 @@ void CustomView::mousePressEvent(QMouseEvent *event)
if (QGraphicsItem *item = itemAt(event->pos())) {
qDebug() << "You clicked on item" << item;
} else {
qDebug() << "You didn't click on an item.";
qDebug("You didn't click on an item.");
}
}
//! [6]

View File

@ -512,7 +512,7 @@ void QGraphicsLinearLayout::setGeometry(const QRectF &rect)
d->engine.setGeometries(effectiveRect, d->styleInfo());
#ifdef QGRIDLAYOUTENGINE_DEBUG
if (qt_graphicsLayoutDebug()) {
qDebug() << "post dump";
qDebug("post dump");
dump(1);
}
#endif

View File

@ -1168,7 +1168,7 @@ void QGraphicsProxyWidget::hoverMoveEvent(QGraphicsSceneHoverEvent *event)
{
Q_D(QGraphicsProxyWidget);
#ifdef GRAPHICSPROXYWIDGET_DEBUG
qDebug() << "QGraphicsProxyWidget::hoverMoveEvent";
qDebug("QGraphicsProxyWidget::hoverMoveEvent");
#endif
// Ignore events on the window frame.
if (!d->widget || !rect().contains(event->pos())) {
@ -1208,7 +1208,7 @@ void QGraphicsProxyWidget::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
Q_D(QGraphicsProxyWidget);
#ifdef GRAPHICSPROXYWIDGET_DEBUG
qDebug() << "QGraphicsProxyWidget::mouseMoveEvent";
qDebug("QGraphicsProxyWidget::mouseMoveEvent");
#endif
d->sendWidgetMouseEvent(event);
}
@ -1220,7 +1220,7 @@ void QGraphicsProxyWidget::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
Q_D(QGraphicsProxyWidget);
#ifdef GRAPHICSPROXYWIDGET_DEBUG
qDebug() << "QGraphicsProxyWidget::mousePressEvent";
qDebug("QGraphicsProxyWidget::mousePressEvent");
#endif
d->sendWidgetMouseEvent(event);
}
@ -1232,7 +1232,7 @@ void QGraphicsProxyWidget::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event
{
Q_D(QGraphicsProxyWidget);
#ifdef GRAPHICSPROXYWIDGET_DEBUG
qDebug() << "QGraphicsProxyWidget::mouseDoubleClickEvent";
qDebug("QGraphicsProxyWidget::mouseDoubleClickEvent");
#endif
d->sendWidgetMouseEvent(event);
}
@ -1245,7 +1245,7 @@ void QGraphicsProxyWidget::wheelEvent(QGraphicsSceneWheelEvent *event)
{
Q_D(QGraphicsProxyWidget);
#ifdef GRAPHICSPROXYWIDGET_DEBUG
qDebug() << "QGraphicsProxyWidget::wheelEvent";
qDebug("QGraphicsProxyWidget::wheelEvent");
#endif
if (!d->widget)
return;
@ -1283,7 +1283,7 @@ void QGraphicsProxyWidget::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
Q_D(QGraphicsProxyWidget);
#ifdef GRAPHICSPROXYWIDGET_DEBUG
qDebug() << "QGraphicsProxyWidget::mouseReleaseEvent";
qDebug("QGraphicsProxyWidget::mouseReleaseEvent");
#endif
d->sendWidgetMouseEvent(event);
}
@ -1295,7 +1295,7 @@ void QGraphicsProxyWidget::keyPressEvent(QKeyEvent *event)
{
Q_D(QGraphicsProxyWidget);
#ifdef GRAPHICSPROXYWIDGET_DEBUG
qDebug() << "QGraphicsProxyWidget::keyPressEvent";
qDebug("QGraphicsProxyWidget::keyPressEvent");
#endif
d->sendWidgetKeyEvent(event);
}
@ -1307,7 +1307,7 @@ void QGraphicsProxyWidget::keyReleaseEvent(QKeyEvent *event)
{
Q_D(QGraphicsProxyWidget);
#ifdef GRAPHICSPROXYWIDGET_DEBUG
qDebug() << "QGraphicsProxyWidget::keyReleaseEvent";
qDebug("QGraphicsProxyWidget::keyReleaseEvent");
#endif
d->sendWidgetKeyEvent(event);
}
@ -1318,7 +1318,7 @@ void QGraphicsProxyWidget::keyReleaseEvent(QKeyEvent *event)
void QGraphicsProxyWidget::focusInEvent(QFocusEvent *event)
{
#ifdef GRAPHICSPROXYWIDGET_DEBUG
qDebug() << "QGraphicsProxyWidget::focusInEvent";
qDebug("QGraphicsProxyWidget::focusInEvent");
#endif
Q_D(QGraphicsProxyWidget);
@ -1357,7 +1357,7 @@ void QGraphicsProxyWidget::focusInEvent(QFocusEvent *event)
void QGraphicsProxyWidget::focusOutEvent(QFocusEvent *event)
{
#ifdef GRAPHICSPROXYWIDGET_DEBUG
qDebug() << "QGraphicsProxyWidget::focusOutEvent";
qDebug("QGraphicsProxyWidget::focusOutEvent");
#endif
Q_D(QGraphicsProxyWidget);
if (d->widget) {

View File

@ -2398,7 +2398,7 @@ bool QGraphicsWidget::close()
#if 0
void QGraphicsWidget::dumpFocusChain()
{
qDebug() << "=========== Dumping focus chain ==============";
qDebug("=========== Dumping focus chain ==============");
int i = 0;
QGraphicsWidget *next = this;
QSet<QGraphicsWidget*> visited;

View File

@ -140,7 +140,7 @@ bool QSimplex::setConstraints(const QList<QSimplexConstraint *> &newConstraints)
// Remove constraints of type Var == K and replace them for their value.
if (!simplifyConstraints(&constraints)) {
qWarning() << "QSimplex: No feasible solution!";
qWarning("QSimplex: No feasible solution!");
clearDataStructures();
return false;
}
@ -230,7 +230,7 @@ bool QSimplex::setConstraints(const QList<QSimplexConstraint *> &newConstraints)
matrix = (qreal *)malloc(sizeof(qreal) * columns * rows);
if (!matrix) {
qWarning() << "QSimplex: Unable to allocate memory!";
qWarning("QSimplex: Unable to allocate memory!");
return false;
}
for (int i = columns * rows - 1; i >= 0; --i)
@ -281,7 +281,7 @@ bool QSimplex::setConstraints(const QList<QSimplexConstraint *> &newConstraints)
// Otherwise, we clean up our structures and report there is
// no feasible solution.
if ((valueAt(0, columns - 1) != 0.0) && (qAbs(valueAt(0, columns - 1)) > 0.00001)) {
qWarning() << "QSimplex: No feasible solution!";
qWarning("QSimplex: No feasible solution!");
clearDataStructures();
return false;
}
@ -471,7 +471,7 @@ bool QSimplex::iterate()
// Find Pivot row for column
int pivotRow = pivotRowForColumn(pivotColumn);
if (pivotRow == -1) {
qWarning() << "QSimplex: Unbounded problem!";
qWarning("QSimplex: Unbounded problem!");
return false;
}

View File

@ -670,13 +670,14 @@ void QTableViewPrivate::trimHiddenSelections(QItemSelectionRange *range) const
void QTableViewPrivate::setSpan(int row, int column, int rowSpan, int columnSpan)
{
if (row < 0 || column < 0 || rowSpan <= 0 || columnSpan <= 0) {
qWarning() << "QTableView::setSpan: invalid span given: (" << row << ',' << column << ',' << rowSpan << ',' << columnSpan << ')';
qWarning("QTableView::setSpan: invalid span given: (%d, %d, %d, %d)",
row, column, rowSpan, columnSpan);
return;
}
QSpanCollection::Span *sp = spans.spanAt(column, row);
if (sp) {
if (sp->top() != row || sp->left() != column) {
qWarning() << "QTableView::setSpan: span cannot overlap";
qWarning("QTableView::setSpan: span cannot overlap");
return;
}
if (rowSpan == 1 && columnSpan == 1) {
@ -688,7 +689,7 @@ void QTableViewPrivate::setSpan(int row, int column, int rowSpan, int columnSpan
spans.updateSpan(sp, old_height);
return;
} else if (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;
}
sp = new QSpanCollection::Span(row, column, rowSpan, columnSpan);

View File

@ -3281,7 +3281,7 @@ QMimeData *QTreeWidget::mimeData(const QList<QTreeWidgetItem*> items) const
for (int i = 0; i < items.count(); ++i) {
QTreeWidgetItem *item = items.at(i);
if (!item) {
qWarning() << "QTreeWidget::mimeData: Null-item passed";
qWarning("QTreeWidget::mimeData: Null-item passed");
return 0;
}

View File

@ -647,8 +647,8 @@ GLuint QOpenGLWidgetPrivate::textureId() const
{
Q_Q(const QOpenGLWidget);
if (!q->isWindow() && q->internalWinId()) {
qWarning() << "QOpenGLWidget cannot be used as a native child widget."
<< "Consider setting Qt::WA_DontCreateNativeAncestors and Qt::AA_DontCreateNativeWidgetSiblings.";
qWarning("QOpenGLWidget cannot be used as a native child widget. Consider setting "
"Qt::WA_DontCreateNativeAncestors and Qt::AA_DontCreateNativeWidgetSiblings");
return 0;
}
return resolvedFbo ? resolvedFbo->texture() : (fbo ? fbo->texture() : 0);

View File

@ -12099,7 +12099,7 @@ QOpenGLContext *QWidgetPrivate::shareContext() const
return 0;
#else
if (!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;
}
QWidgetPrivate *that = const_cast<QWidgetPrivate *>(this);

View File

@ -7191,7 +7191,7 @@ CGContextRef qt_mac_cg_context(const QPaintDevice *pdev)
ret = CGBitmapContextCreate(image->bits(), image->width(), image->height(),
8, image->bytesPerLine(), colorspace, flags);
} else {
qDebug() << "qt_mac_cg_context: Unsupported pixmap class";
qDebug("qt_mac_cg_context: Unsupported pixmap class");
}
CGContextTranslateCTM(ret, 0, pm->height());
@ -7203,7 +7203,7 @@ CGContextRef qt_mac_cg_context(const QPaintDevice *pdev)
//CGContextRef ret = static_cast<CGContextRef>(static_cast<const QWidget *>(pdev)->macCGHandle());
///CGContextRetain(ret);
//return ret;
qDebug() << "qt_mac_cg_context: not implemented: Widget class";
qDebug("qt_mac_cg_context: not implemented: Widget class");
return 0;
}
return 0;

View File

@ -155,9 +155,9 @@ public:
mouseTarget = QApplication::widgetAt(pressDelayEvent->globalPos());
mouseButton = pressDelayEvent->button();
mouseEventSource = pressDelayEvent->source();
qFGDebug() << "QFG: consuming/delaying mouse press";
qFGDebug("QFG: consuming/delaying mouse press");
} else {
qFGDebug() << "QFG: NOT consuming/delaying mouse press";
qFGDebug("QFG: NOT consuming/delaying mouse press");
}
e->setAccepted(true);
}
@ -194,7 +194,7 @@ public:
void scrollerWasIntercepted()
{
qFGDebug() << "QFG: deleting delayed mouse press, since scroller was only intercepted";
qFGDebug("QFG: deleting delayed mouse press, since scroller was only intercepted");
if (pressDelayEvent) {
// we still haven't even sent the press, so just throw it away now
if (pressDelayTimer) {
@ -210,7 +210,7 @@ public:
{
if (pressDelayEvent) {
// we still haven't even sent the press, so just throw it away now
qFGDebug() << "QFG: deleting delayed mouse press, since scroller is active now";
qFGDebug("QFG: deleting delayed mouse press, since scroller is active now");
if (pressDelayTimer) {
killTimer(pressDelayTimer);
pressDelayTimer = 0;

View File

@ -1668,7 +1668,7 @@ bool QScrollerPrivate::releaseWhileDragging(const QPointF &position, qint64 time
void QScrollerPrivate::timerEventWhileScrolling()
{
qScrollerDebug() << "QScroller::timerEventWhileScrolling()";
qScrollerDebug("QScroller::timerEventWhileScrolling()");
setContentPositionHelperScrolling();
if (xSegments.isEmpty() && ySegments.isEmpty())

View File

@ -245,7 +245,7 @@ bool QDockWidgetLayout::nativeWindowDeco(bool floating) const
void QDockWidgetLayout::addItem(QLayoutItem*)
{
qWarning() << "QDockWidgetLayout::addItem(): please use QDockWidgetLayout::setWidget()";
qWarning("QDockWidgetLayout::addItem(): please use QDockWidgetLayout::setWidget()");
return;
}

View File

@ -153,7 +153,7 @@ void QToolBarLayout::checkUsePopupMenu()
void QToolBarLayout::addItem(QLayoutItem*)
{
qWarning() << "QToolBarLayout::addItem(): please use addAction() instead";
qWarning("QToolBarLayout::addItem(): please use addAction() instead");
return;
}