QDebug::toString(): use nospace()
The intended use cases for toString() are the situations where you can't use operator<<, such as QVERIFY2, Q_ASSERT_X, etc., which means that it will often be used as an argument to e.g. QString::arg(), where the user has control over the structure of the message. For that reason, adding an extra space to the end is not necessary and just gets in the way. This amends 658b9697f9d85d4ed294810b4f60bafdbdd8e247. Change-Id: I0695e6809026a0f92ed783899da80de4fa2a1684 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
This commit is contained in:
parent
7ef6ddaf7a
commit
981c1fe15f
@ -5,3 +5,5 @@ This function is useful for cases where you need the textual representation
|
||||
of an object for debugging, but cannot use \c {operator<<}. For example:
|
||||
|
||||
\snippet code/src_corelib_io_qdebug.cpp toString
|
||||
|
||||
The string is streamed using \l nospace().
|
||||
|
@ -179,7 +179,7 @@ public:
|
||||
{
|
||||
QString buffer;
|
||||
QDebug stream(&buffer);
|
||||
stream << object;
|
||||
stream.nospace() << object;
|
||||
return buffer;
|
||||
}
|
||||
|
||||
@ -188,7 +188,7 @@ public:
|
||||
{
|
||||
QString buffer;
|
||||
QDebug stream(&buffer);
|
||||
stream << object;
|
||||
stream.nospace() << object;
|
||||
return buffer;
|
||||
}
|
||||
};
|
||||
|
@ -748,7 +748,7 @@ void tst_QDebug::toString() const
|
||||
MyPoint point(3, 4);
|
||||
QString expectedString;
|
||||
QDebug stream(&expectedString);
|
||||
stream << point;
|
||||
stream.nospace() << point;
|
||||
QCOMPARE(QDebug::toString(point), expectedString);
|
||||
}
|
||||
|
||||
@ -758,7 +758,7 @@ void tst_QDebug::toString() const
|
||||
qobject.setObjectName("test");
|
||||
QString expectedString;
|
||||
QDebug stream(&expectedString);
|
||||
stream << &qobject;
|
||||
stream.nospace() << &qobject;
|
||||
QCOMPARE(QDebug::toString(&qobject), expectedString);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user