Use QVERIFY2(condition, qPrintable(...))
when using a QString.
The second argument must be a const char *
. In all of your cases you're creating a QString instead -- which is indeed very convenient because it allows you to use +
for concatenation, or QString::arg()
, etc; you need a conversion to char *
, which is not implicit, and that's what qPrintable()
does.
To elaborate: qPrintable(string)
is a shorthand for string.toLocal8Bit().constData()
. Qt 5.4 will also introduce qUtf8Printable(string)
which is the equivalent of string.toUtf8().constData()
.
Addendum: apart from the technicality of what to pass to QVERIFY2
, why aren't you using QCOMPARE(spy.count(), 1)
? In case of failure it will emit the expected value and the actual value.