抱歉标题不好,我不知道如何命名这个问题。请编辑并使其变得更好。
我正在使用 Qt 测试框架编写测试,并且正在尝试编写一些有用的输出以供QVERIFY2()
宏使用。以下所有语句都未能通过大致相同的错误消息进行编译:
QVERIFY2( spy.count() == 1, "Emitted signal pathChanged() was emitted " + spy.count() + " times instead of 1 time" );
QVERIFY2( spy.count() == 1, QString( "Emitted signal pathChanged() was emitted " ) + QString( spy.count() ) + QString( " times instead of 1 time" ) );
QVERIFY2( spy.count() == 1, "Emitted signal pathChanged() was emitted " + QString( spy.count() ) + " times instead of 1 time" );
最后一次尝试的错误消息是:
PathTester.cxx: In member function ‘void PathTester::testReservePath()’:
PathTester.cxx:241:128: error: cannot convert ‘QString’ to ‘const char*’ for argument ‘3’ to ‘bool QTest::qVerify(bool, const char*, const char*, const char*, int)’
PathTester.cxx:241:243: error: cannot convert ‘QString’ to ‘const char*’ for argument ‘3’ to ‘bool QTest::qVerify(bool, const char*, const char*, const char*, int)’
我究竟做错了什么?我怎样才能正确地写出来?