QTest Namespace The QTest namespace contains all the functions and declarations that are related to Qt Test. More... Header: #include <QTest> qmake: QT += testlib Obsolete members Classes class QTouchEventSequence Types enum AttributeIndex { AI_Undefined, AI_Name, AI_Result, AI_Tests, AI_Failures, …, AI_Iterations } enum KeyAction { Press, Release, Click, Shortcut } enum LogElementType { LET_Undefined, LET_Property, LET_Properties, LET_Failure, LET_Error, …, LET_SystemError } enum MouseAction { MousePress, MouseRelease, MouseClick, MouseDClick, MouseMove } enum QBenchmarkMetric { FramesPerSecond, BitsPerSecond, BytesPerSecond, WalltimeMilliseconds, WalltimeNanoseconds, …, EmulationFaults } enum TestFailMode { Abort, Continue } Functions void addColumn(const char *name, T *dummy = ...) QTestData & addRow(const char *format, ...) const char * benchmarkMetricName(QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069QBenchmarkMetric metric) const char * benchmarkMetricUnit(QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069QBenchmarkMetric metric) QTouchDevice * createTouchDevice(QTouchDevi8b7c:f320:99b9:690f:4595:cd17:293a:c069DeviceType devType = ...) const char * currentAppName() const char * currentDataTag() bool currentTestFailed() const char * currentTestFunction() void ignoreMessage(QtMsgType type, const char *message) void ignoreMessage(QtMsgType type, const QRegularExpression &messagePattern) void keyClick(QWidget *widget, Qt8b7c:f320:99b9:690f:4595:cd17:293a:c069Key key, Qt8b7c:f320:99b9:690f:4595:cd17:293a:c069KeyboardModifiers modifier = ..., int delay = ...) void keyClick(QWindow *window, Qt8b7c:f320:99b9:690f:4595:cd17:293a:c069Key key, Qt8b7c:f320:99b9:690f:4595:cd17:293a:c069KeyboardModifiers modifier = ..., int delay = ...) void keyClick(QWindow *window, char key, Qt8b7c:f320:99b9:690f:4595:cd17:293a:c069KeyboardModifiers modifier = ..., int delay = ...) void keyClick(QWidget *widget, char key, Qt8b7c:f320:99b9:690f:4595:cd17:293a:c069KeyboardModifiers modifier = ..., int delay = ...) void keyClicks(QWidget *widget, const QString &sequence, Qt8b7c:f320:99b9:690f:4595:cd17:293a:c069KeyboardModifiers modifier = ..., int delay = ...) void keyEvent(QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069KeyAction action, QWidget *widget, Qt8b7c:f320:99b9:690f:4595:cd17:293a:c069Key key, Qt8b7c:f320:99b9:690f:4595:cd17:293a:c069KeyboardModifiers modifier = ..., int delay = ...) void keyEvent(QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069KeyAction action, QWindow *window, char ascii, Qt8b7c:f320:99b9:690f:4595:cd17:293a:c069KeyboardModifiers modifier = ..., int delay = ...) void keyEvent(QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069KeyAction action, QWindow *window, Qt8b7c:f320:99b9:690f:4595:cd17:293a:c069Key key, Qt8b7c:f320:99b9:690f:4595:cd17:293a:c069KeyboardModifiers modifier = ..., int delay = ...) void keyEvent(QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069KeyAction action, QWidget *widget, char ascii, Qt8b7c:f320:99b9:690f:4595:cd17:293a:c069KeyboardModifiers modifier = ..., int delay = ...) void keyPress(QWidget *widget, Qt8b7c:f320:99b9:690f:4595:cd17:293a:c069Key key, Qt8b7c:f320:99b9:690f:4595:cd17:293a:c069KeyboardModifiers modifier = ..., int delay = ...) void keyPress(QWindow *window, char key, Qt8b7c:f320:99b9:690f:4595:cd17:293a:c069KeyboardModifiers modifier = ..., int delay = ...) void keyPress(QWindow *window, Qt8b7c:f320:99b9:690f:4595:cd17:293a:c069Key key, Qt8b7c:f320:99b9:690f:4595:cd17:293a:c069KeyboardModifiers modifier = ..., int delay = ...) void keyPress(QWidget *widget, char key, Qt8b7c:f320:99b9:690f:4595:cd17:293a:c069KeyboardModifiers modifier = ..., int delay = ...) void keyRelease(QWidget *widget, Qt8b7c:f320:99b9:690f:4595:cd17:293a:c069Key key, Qt8b7c:f320:99b9:690f:4595:cd17:293a:c069KeyboardModifiers modifier = ..., int delay = ...) void keyRelease(QWindow *window, char key, Qt8b7c:f320:99b9:690f:4595:cd17:293a:c069KeyboardModifiers modifier = ..., int delay = ...) void keyRelease(QWindow *window, Qt8b7c:f320:99b9:690f:4595:cd17:293a:c069Key key, Qt8b7c:f320:99b9:690f:4595:cd17:293a:c069KeyboardModifiers modifier = ..., int delay = ...) void keyRelease(QWidget *widget, char key, Qt8b7c:f320:99b9:690f:4595:cd17:293a:c069KeyboardModifiers modifier = ..., int delay = ...) void keySequence(QWindow *window, const QKeySequence &keySequence) void keySequence(QWidget *widget, const QKeySequence &keySequence) void mouseClick(QWidget *widget, Qt8b7c:f320:99b9:690f:4595:cd17:293a:c069MouseButton button, Qt8b7c:f320:99b9:690f:4595:cd17:293a:c069KeyboardModifiers modifier = ..., QPoint pos = ..., int delay = ...) void mouseClick(QWindow *window, Qt8b7c:f320:99b9:690f:4595:cd17:293a:c069MouseButton button, Qt8b7c:f320:99b9:690f:4595:cd17:293a:c069KeyboardModifiers stateKey = ..., QPoint pos = ..., int delay = ...) void mouseDClick(QWidget *widget, Qt8b7c:f320:99b9:690f:4595:cd17:293a:c069MouseButton button, Qt8b7c:f320:99b9:690f:4595:cd17:293a:c069KeyboardModifiers modifier = ..., QPoint pos = ..., int delay = ...) void mouseDClick(QWindow *window, Qt8b7c:f320:99b9:690f:4595:cd17:293a:c069MouseButton button, Qt8b7c:f320:99b9:690f:4595:cd17:293a:c069KeyboardModifiers stateKey = ..., QPoint pos = ..., int delay = ...) void mouseMove(QWidget *widget, QPoint pos = ..., int delay = ...) void mouseMove(QWindow *window, QPoint pos = ..., int delay = ...) void mousePress(QWidget *widget, Qt8b7c:f320:99b9:690f:4595:cd17:293a:c069MouseButton button, Qt8b7c:f320:99b9:690f:4595:cd17:293a:c069KeyboardModifiers modifier = ..., QPoint pos = ..., int delay = ...) void mousePress(QWindow *window, Qt8b7c:f320:99b9:690f:4595:cd17:293a:c069MouseButton button, Qt8b7c:f320:99b9:690f:4595:cd17:293a:c069KeyboardModifiers stateKey = ..., QPoint pos = ..., int delay = ...) void mouseRelease(QWidget *widget, Qt8b7c:f320:99b9:690f:4595:cd17:293a:c069MouseButton button, Qt8b7c:f320:99b9:690f:4595:cd17:293a:c069KeyboardModifiers modifier = ..., QPoint pos = ..., int delay = ...) void mouseRelease(QWindow *window, Qt8b7c:f320:99b9:690f:4595:cd17:293a:c069MouseButton button, Qt8b7c:f320:99b9:690f:4595:cd17:293a:c069KeyboardModifiers stateKey = ..., QPoint pos = ..., int delay = ...) QTestData & newRow(const char *dataTag) int qExec(QObject *testObject, int argc = 0, char **argv = nullptr) int qExec(QObject *testObject, const QStringList &arguments) QSharedPointer<QTemporaryDir> qExtractTestData(const QString &dirName) void qSleep(int ms) void qWait(int ms) bool qWaitFor(Functor predicate, int timeout = 5000) bool qWaitForWindowActive(QWindow *window, int timeout = 5000) bool qWaitForWindowActive(QWidget *widget, int timeout = 5000) bool qWaitForWindowExposed(QWindow *window, int timeout = 5000) bool qWaitForWindowExposed(QWidget *widget, int timeout = 5000) void setBenchmarkResult(qreal result, QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069QBenchmarkMetric metric) char * toHexRepresentation(const char *ba, int length) char * toString(const T &value) char * toString(const QPair<T1, T2> &pair) char * toString(QSizePolicy8b7c:f320:99b9:690f:4595:cd17:293a:c069ontrolTypes cts) char * toString(QSizePolicy8b7c:f320:99b9:690f:4595:cd17:293a:c069ontrolType ct) char * toString(QSizePolicy sp) char * toString(const st8b7c:f320:99b9:690f:4595:cd17:293a:c069pair<T1, T2> &pair) char * toString(const st8b7c:f320:99b9:690f:4595:cd17:293a:c069tuple<Types...> &tuple) char * toString(const QStringView &string) char * toString(const QString &string) char * toString(const QLatin1String &string) char * toString(const QByteArray &ba) char * toString(const QTime &time) char * toString(const QDate &date) char * toString(const QDateTime &dateTime) char * toString(const QCborError &c) char * toString(const QChar &character) char * toString(const QPoint &point) char * toString(const QSize &size) char * toString(const QRect &rectangle) char * toString(const QPointF &point) char * toString(const QSizeF &size) char * toString(const QRectF &rectangle) char * toString(const QUrl &url) char * toString(const QUuid &uuid) char * toString(const QVariant &variant) char * toString(st8b7c:f320:99b9:690f:4595:cd17:293a:c069nullptr_t) char * toString(const QVector2D &v) char * toString(const QVector3D &v) char * toString(const QVector4D &v) char * toString(QSizePolicy8b7c:f320:99b9:690f:4595:cd17:293a:c069Policy p) QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069QTouchEventSequence touchEvent(QWidget *widget, QTouchDevice *device, bool autoCommit) QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069QTouchEventSequence touchEvent(QWindow *window, QTouchDevice *device, bool autoCommit) Macros QBENCHMARK QBENCHMARK_ONCE QCOMPARE(actual, expected) QEXPECT_FAIL(dataIndex, comment, mode) QFAIL(message) QFETCH(type, name) QFETCH_GLOBAL(type, name) QFINDTESTDATA(filename) QSKIP(description) QTEST(actual, testElement) QTEST_APPLESS_MAIN(TestClass) QTEST_GUILESS_MAIN(TestClass) QTEST_MAIN(TestClass) QTRY_COMPARE(actual, expected) QTRY_COMPARE_WITH_TIMEOUT(actual, expected, timeout) QTRY_VERIFY2(condition, message) QTRY_VERIFY(condition) QTRY_VERIFY2_WITH_TIMEOUT(condition, message, timeout) QTRY_VERIFY_WITH_TIMEOUT(condition, timeout) QVERIFY2(condition, message) QVERIFY(condition) QVERIFY_EXCEPTION_THROWN(expression, exceptiontype) QWARN(message) Detailed Description See the Qt Test Overview for information about how to write unit tests. Classes class QTouchEventSequence The QTouchEventSequence class is used to simulate a sequence of touch events. More... Type Documentation enum QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069ttributeIndex This enum numbers the different tests. Constant Value QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069I_Undefined -1 QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069I_Name 0 QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069I_Result 1 QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069I_Tests 2 QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069I_Failures 3 QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069I_Errors 4 QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069I_Type 5 QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069I_Description 6 QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069I_PropertyValue 7 QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069I_QTestVersion 8 QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069I_QtVersion 9 QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069I_File 10 QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069I_Line 11 QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069I_Metric 12 QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069I_Tag 13 QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069I_Value 14 QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069I_Iterations 15 enum QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069KeyAction This enum describes possible actions for key handling. Constant Value Description QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069Press 0 The key is pressed. QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069Release 1 The key is released. QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069lick 2 The key is clicked (pressed and released). QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069Shortcut 3 A shortcut is activated. This value has been added in Qt 5.6. enum QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069LogElementType The enum specifies the kinds of test log messages. Constant Value QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069LET_Undefined -1 QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069LET_Property 0 QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069LET_Properties 1 QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069LET_Failure 2 QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069LET_Error 3 QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069LET_TestCase 4 QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069LET_TestSuite 5 QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069LET_Benchmark 6 QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069LET_SystemError 7 enum QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069MouseAction This enum describes possible actions for mouse handling. Constant Value Description QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069MousePress 0 A mouse button is pressed. QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069MouseRelease 1 A mouse button is released. QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069MouseClick 2 A mouse button is clicked (pressed and released). QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069MouseDClick 3 A mouse button is double clicked (pressed and released twice). QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069MouseMove 4 The mouse pointer has moved. enum QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069QBenchmarkMetric This enum lists all the things that can be benchmarked. Constant Value Description QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069ramesPerSecond 0 Frames per second QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069itsPerSecond 1 Bits per second QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069ytesPerSecond 2 Bytes per second QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069WalltimeMilliseconds 3 Clock time in milliseconds QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069WalltimeNanoseconds 7 Clock time in nanoseconds QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069ytesAllocated 8 Memory usage in bytes QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069vents 6 Event count QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069PUTicks 4 CPU time QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069PUMigrations 9 Process migrations between CPUs QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069PUCycles 10 CPU cycles QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069RefCPUCycles 30 Reference CPU cycles QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069usCycles 11 Bus cycles QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069StalledCycles 12 Cycles stalled QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069InstructionReads 5 Instruction reads QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069Instructions 13 Instructions executed QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069ranchInstructions 14 Branch-type instructions QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069ranchMisses 15 Branch instructions that were mispredicted QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069heReferences 16 Cache accesses of any type QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069heMisses 20 Cache misses of any type QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069heReads 17 Cache reads / loads QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069heReadMisses 21 Cache read / load misses QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069heWrites 18 Cache writes / stores QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069heWriteMisses 22 Cache write / store misses QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069hePrefetches 19 Cache prefetches QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069hePrefetchMisses 23 Cache prefetch misses QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069ontextSwitches 24 Context switches QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069PageFaults 25 Page faults of any type QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069MinorPageFaults 26 Minor page faults QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069MajorPageFaults 27 Major page faults QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069lignmentFaults 28 Faults caused due to misalignment QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069mulationFaults 29 Faults that needed software emulation Note that WalltimeNanoseconds and BytesAllocated are only provided for use via setBenchmarkResult(), and results in those metrics are not able to be provided automatically by the QTest framework. This enum was introduced or modified in Qt 4.7. See also QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069nchmarkMetricName() and QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069nchmarkMetricUnit(). enum QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069TestFailMode This enum describes the modes for handling an expected failure of the QVERIFY() or QCOMPARE() macros. Constant Value Description QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069ort 1 Aborts the execution of the test. Use this mode when it doesn't make sense to execute the test any further after the expected failure. QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069ontinue 2 Continues execution of the test after the expected failure. See also QEXPECT_FAIL(). Function Documentation void QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069olumn(const char *name, T *dummy = ...) Adds a column with type T to the current test data. name is the name of the column. dummy is a workaround for buggy compilers and can be ignored. To populate the column with values, newRow() can be used. Use QFETCH() to fetch the data in the actual test. Example: void myTestFunction_data() { QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069olumn<int>("intval"); QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069olumn<QString>("str"); QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069olumn<double>("dbl"); QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069newRow("row1") << 1 << "hello" << 1.5; } To add custom types to the testdata, the type must be registered with QMetaType via Q_DECLARE_METATYPE(). Note: This macro can only be used in a test's data function that is invoked by the test framework. See Data Driven Testing for a more extensive example. See also QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069newRow(), QFETCH(), and QMetaType. QTestData &QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069Row(const char *format, ...) Appends a new row to the current test data. The function's arguments are passed to qsnprintf() for formatting according to format. See the qvsnprintf() documentation for caveats and limitations. The formatted string will appear as the name of this test data in the test output. Returns a QTestData reference that can be used to stream in data. Example: void myTestFunction_data() { QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069olumn<int>("input"); QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069olumn<QString>("output"); QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069Row("%d", 0) << 0 << QString("0"); QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069Row("%d", 1) << 1 << QString("1"); } Note: This function can only be used in a test's data function that is invoked by the test framework. See Data Driven Testing for a more extensive example. This function was introduced in Qt 5.9. See also addColumn() and QFETCH(). const char *QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069nchmarkMetricName(QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069QBenchmarkMetric metric) Returns the enum value metric as a character string. This function was introduced in Qt 4.7. const char *QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069nchmarkMetricUnit(QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069QBenchmarkMetric metric) Retuns the units of measure for the specified metric. This function was introduced in Qt 4.7. QTouchDevice *QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069reateTouchDevice(QTouchDevi8b7c:f320:99b9:690f:4595:cd17:293a:c069DeviceType devType = ...) Creates a dummy touch device of type devType for simulation of touch events. The touch device will be registered with the QPA window system interface, and deleted automatically when the QCoreApplication is deleted. So you should typically use createTouchDevice() to initialize a QTouchDevice member variable in your test case class, and use the same instance for all tests. This function was introduced in Qt 5.8. See also QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069QTouchEventSequence. const char *QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069urrentAppName() Returns the name of the binary that is currently executed. const char *QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069urrentDataTag() Returns the name of the current test data. If the test doesn't have any assigned testdata, the function returns 0. bool QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069urrentTestFailed() Returns true if the current test function failed, otherwise false. const char *QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069urrentTestFunction() Returns the name of the test function that is currently executed. Example: void MyTestClass8b7c:f320:99b9:690f:4595:cd17:293a:c069leanup() { if (qstrcmp(currentTestFunction(), "myDatabaseTest") == 0) { // clean up all database connections closeAllDatabases(); } } void QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069ignoreMessage(QtMsgType type, const char *message) Ignores messages created by qDebug(), qInfo() or qWarning(). If the message with the corresponding type is outputted, it will be removed from the test log. If the test finished and the message was not outputted, a test failure is appended to the test log. Note: Invoking this function will only ignore one message. If the message you want to ignore is outputted twice, you have to call ignoreMessage() twice, too. Example: QDir dir; QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069ignoreMessage(QtWarningMsg, "QDir8b7c:f320:99b9:690f:4595:cd17:293a:c069mkdir: Empty or null file name(s)"); dir.mkdir(""); The example above tests that QDir8b7c:f320:99b9:690f:4595:cd17:293a:c069mkdir() outputs the right warning when invoked with an invalid file name. void QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069ignoreMessage(QtMsgType type, const QRegularExpression &messagePattern) This is an overloaded function. Ignores messages created by qDebug(), qInfo() or qWarning(). If the message matching messagePattern with the corresponding type is outputted, it will be removed from the test log. If the test finished and the message was not outputted, a test failure is appended to the test log. Note: Invoking this function will only ignore one message. If the message you want to ignore is outputted twice, you have to call ignoreMessage() twice, too. This function was introduced in Qt 5.3. void QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069keyClick(QWidget *widget, Qt8b7c:f320:99b9:690f:4595:cd17:293a:c069Key key, Qt8b7c:f320:99b9:690f:4595:cd17:293a:c069KeyboardModifiers modifier = ..., int delay = ...) Simulates clicking of key with an optional modifier on a widget. If delay is larger than 0, the test will wait for delay milliseconds before clicking the key. Examples: QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069keyClick(myWidget, Qt8b7c:f320:99b9:690f:4595:cd17:293a:c069Key_Escape); QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069keyClick(myWidget, Qt8b7c:f320:99b9:690f:4595:cd17:293a:c069Key_Escape, Qt8b7c:f320:99b9:690f:4595:cd17:293a:c069ShiftModifier, 200); The first example above simulates clicking the escape key on myWidget without any keyboard modifiers and without delay. The second example simulates clicking shift-escape on myWidget following a 200 ms delay of the test. See also QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069keyClicks(). void QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069keyClick(QWindow *window, Qt8b7c:f320:99b9:690f:4595:cd17:293a:c069Key key, Qt8b7c:f320:99b9:690f:4595:cd17:293a:c069KeyboardModifiers modifier = ..., int delay = ...) This is an overloaded function. Simulates clicking of key with an optional modifier on a window. If delay is larger than 0, the test will wait for delay milliseconds before clicking the key. Examples: QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069keyClick(myWindow, Qt8b7c:f320:99b9:690f:4595:cd17:293a:c069Key_Escape); QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069keyClick(myWindow, Qt8b7c:f320:99b9:690f:4595:cd17:293a:c069Key_Escape, Qt8b7c:f320:99b9:690f:4595:cd17:293a:c069ShiftModifier, 200); The first example above simulates clicking the escape key on myWindow without any keyboard modifiers and without delay. The second example simulates clicking shift-escape on myWindow following a 200 ms delay of the test. This function was introduced in Qt 5.0. See also QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069keyClicks(). void QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069keyClick(QWindow *window, char key, Qt8b7c:f320:99b9:690f:4595:cd17:293a:c069KeyboardModifiers modifier = ..., int delay = ...) This is an overloaded function. Simulates clicking of key with an optional modifier on a window. If delay is larger than 0, the test will wait for delay milliseconds before clicking the key. Example: QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069keyClick(myWindow, 'a'); The example above simulates clicking a on myWindow without any keyboard modifiers and without delay of the test. This function was introduced in Qt 5.0. See also QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069keyClicks(). void QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069keyClick(QWidget *widget, char key, Qt8b7c:f320:99b9:690f:4595:cd17:293a:c069KeyboardModifiers modifier = ..., int delay = ...) This is an overloaded function. Simulates clicking of key with an optional modifier on a widget. If delay is larger than 0, the test will wait for delay milliseconds before clicking the key. Example: QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069keyClick(myWidget, 'a'); The example above simulates clicking a on myWidget without any keyboard modifiers and without delay of the test. See also QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069keyClicks(). void QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069keyClicks(QWidget *widget, const QString &sequence, Qt8b7c:f320:99b9:690f:4595:cd17:293a:c069KeyboardModifiers modifier = ..., int delay = ...) Simulates clicking a sequence of keys on a widget. Optionally, a keyboard modifier can be specified as well as a delay (in milliseconds) of the test before each key click. Example: QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069keyClicks(myWidget, "hello world"); The example above simulates clicking the sequence of keys representing "hello world" on myWidget without any keyboard modifiers and without delay of the test. See also QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069keyClick(). void QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069keyEvent(QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069KeyAction action, QWidget *widget, Qt8b7c:f320:99b9:690f:4595:cd17:293a:c069Key key, Qt8b7c:f320:99b9:690f:4595:cd17:293a:c069KeyboardModifiers modifier = ..., int delay = ...) Sends a Qt key event to widget with the given key and an associated action. Optionally, a keyboard modifier can be specified, as well as a delay (in milliseconds) of the test before sending the event. void QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069keyEvent(QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069KeyAction action, QWindow *window, char ascii, Qt8b7c:f320:99b9:690f:4595:cd17:293a:c069KeyboardModifiers modifier = ..., int delay = ...) This is an overloaded function. Sends a Qt key event to window with the given key ascii and an associated action. Optionally, a keyboard modifier can be specified, as well as a delay (in milliseconds) of the test before sending the event. This function was introduced in Qt 5.0. void QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069keyEvent(QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069KeyAction action, QWindow *window, Qt8b7c:f320:99b9:690f:4595:cd17:293a:c069Key key, Qt8b7c:f320:99b9:690f:4595:cd17:293a:c069KeyboardModifiers modifier = ..., int delay = ...) This is an overloaded function. Sends a Qt key event to window with the given key and an associated action. Optionally, a keyboard modifier can be specified, as well as a delay (in milliseconds) of the test before sending the event. This function was introduced in Qt 5.0. void QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069keyEvent(QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069KeyAction action, QWidget *widget, char ascii, Qt8b7c:f320:99b9:690f:4595:cd17:293a:c069KeyboardModifiers modifier = ..., int delay = ...) This is an overloaded function. Sends a Qt key event to widget with the given key ascii and an associated action. Optionally, a keyboard modifier can be specified, as well as a delay (in milliseconds) of the test before sending the event. void QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069keyPress(QWidget *widget, Qt8b7c:f320:99b9:690f:4595:cd17:293a:c069Key key, Qt8b7c:f320:99b9:690f:4595:cd17:293a:c069KeyboardModifiers modifier = ..., int delay = ...) Simulates pressing a key with an optional modifier on a widget. If delay is larger than 0, the test will wait for delay milliseconds before pressing the key. Note: At some point you should release the key using keyRelease(). See also QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069keyRelease() and QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069keyClick(). void QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069keyPress(QWindow *window, char key, Qt8b7c:f320:99b9:690f:4595:cd17:293a:c069KeyboardModifiers modifier = ..., int delay = ...) This is an overloaded function. Simulates pressing a key with an optional modifier on a window. If delay is larger than 0, the test will wait for delay milliseconds before pressing the key. Note: At some point you should release the key using keyRelease(). This function was introduced in Qt 5.0. See also QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069keyRelease() and QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069keyClick(). void QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069keyPress(QWindow *window, Qt8b7c:f320:99b9:690f:4595:cd17:293a:c069Key key, Qt8b7c:f320:99b9:690f:4595:cd17:293a:c069KeyboardModifiers modifier = ..., int delay = ...) This is an overloaded function. Simulates pressing a key with an optional modifier on a window. If delay is larger than 0, the test will wait for delay milliseconds before pressing the key. Note: At some point you should release the key using keyRelease(). This function was introduced in Qt 5.0. See also QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069keyRelease() and QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069keyClick(). void QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069keyPress(QWidget *widget, char key, Qt8b7c:f320:99b9:690f:4595:cd17:293a:c069KeyboardModifiers modifier = ..., int delay = ...) This is an overloaded function. Simulates pressing a key with an optional modifier on a widget. If delay is larger than 0, the test will wait for delay milliseconds before pressing the key. Note: At some point you should release the key using keyRelease(). See also QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069keyRelease() and QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069keyClick(). void QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069keyRelease(QWidget *widget, Qt8b7c:f320:99b9:690f:4595:cd17:293a:c069Key key, Qt8b7c:f320:99b9:690f:4595:cd17:293a:c069KeyboardModifiers modifier = ..., int delay = ...) Simulates releasing a key with an optional modifier on a widget. If delay is larger than 0, the test will wait for delay milliseconds before releasing the key. See also QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069keyPress() and QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069keyClick(). void QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069keyRelease(QWindow *window, char key, Qt8b7c:f320:99b9:690f:4595:cd17:293a:c069KeyboardModifiers modifier = ..., int delay = ...) This is an overloaded function. Simulates releasing a key with an optional modifier on a window. If delay is larger than 0, the test will wait for delay milliseconds before releasing the key. This function was introduced in Qt 5.0. See also QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069keyClick(). void QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069keyRelease(QWindow *window, Qt8b7c:f320:99b9:690f:4595:cd17:293a:c069Key key, Qt8b7c:f320:99b9:690f:4595:cd17:293a:c069KeyboardModifiers modifier = ..., int delay = ...) This is an overloaded function. Simulates releasing a key with an optional modifier on a window. If delay is larger than 0, the test will wait for delay milliseconds before releasing the key. This function was introduced in Qt 5.0. See also QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069keyPress() and QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069keyClick(). void QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069keyRelease(QWidget *widget, char key, Qt8b7c:f320:99b9:690f:4595:cd17:293a:c069KeyboardModifiers modifier = ..., int delay = ...) This is an overloaded function. Simulates releasing a key with an optional modifier on a widget. If delay is larger than 0, the test will wait for delay milliseconds before releasing the key. See also QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069keyClick(). void QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069keySequence(QWindow *window, const QKeySequence &keySequence) This is an overloaded function. Simulates typing of keySequence into a window. This function was introduced in Qt 5.10. See also QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069keyClick() and QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069keyClicks(). void QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069keySequence(QWidget *widget, const QKeySequence &keySequence) This is an overloaded function. Simulates typing of keySequence into a widget. This function was introduced in Qt 5.10. See also QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069keyClick() and QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069keyClicks(). void QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069mouseClick(QWidget *widget, Qt8b7c:f320:99b9:690f:4595:cd17:293a:c069MouseButton button, Qt8b7c:f320:99b9:690f:4595:cd17:293a:c069KeyboardModifiers modifier = ..., QPoint pos = ..., int delay = ...) Simulates clicking a mouse button with an optional modifier on a widget. The position of the click is defined by pos; the default position is the center of the widget. If delay is specified, the test will wait for the specified amount of milliseconds before pressing and before releasing the button. See also QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069mousePress() and QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069mouseRelease(). void QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069mouseClick(QWindow *window, Qt8b7c:f320:99b9:690f:4595:cd17:293a:c069MouseButton button, Qt8b7c:f320:99b9:690f:4595:cd17:293a:c069KeyboardModifiers stateKey = ..., QPoint pos = ..., int delay = ...) This is an overloaded function. Simulates clicking a mouse button with an optional stateKey modifier on a window. The position of the click is defined by pos; the default position is the center of the window. If delay is specified, the test will wait for the specified amount of milliseconds before pressing and before releasing the button. This function was introduced in Qt 5.0. See also QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069mousePress() and QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069mouseRelease(). void QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069mouseDClick(QWidget *widget, Qt8b7c:f320:99b9:690f:4595:cd17:293a:c069MouseButton button, Qt8b7c:f320:99b9:690f:4595:cd17:293a:c069KeyboardModifiers modifier = ..., QPoint pos = ..., int delay = ...) Simulates double clicking a mouse button with an optional modifier on a widget. The position of the click is defined by pos; the default position is the center of the widget. If delay is specified, the test will wait for the specified amount of milliseconds before each press and release. See also QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069mouseClick(). void QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069mouseDClick(QWindow *window, Qt8b7c:f320:99b9:690f:4595:cd17:293a:c069MouseButton button, Qt8b7c:f320:99b9:690f:4595:cd17:293a:c069KeyboardModifiers stateKey = ..., QPoint pos = ..., int delay = ...) This is an overloaded function. Simulates double clicking a mouse button with an optional stateKey modifier on a window. The position of the click is defined by pos; the default position is the center of the window. If delay is specified, the test will wait for the specified amount of milliseconds before each press and release. This function was introduced in Qt 5.0. See also QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069mouseClick(). void QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069mouseMove(QWidget *widget, QPoint pos = ..., int delay = ...) Moves the mouse pointer to a widget. If pos is not specified, the mouse pointer moves to the center of the widget. If a delay (in milliseconds) is given, the test will wait before moving the mouse pointer. void QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069mouseMove(QWindow *window, QPoint pos = ..., int delay = ...) This is an overloaded function. Moves the mouse pointer to a window. If pos is not specified, the mouse pointer moves to the center of the window. If a delay (in milliseconds) is given, the test will wait before moving the mouse pointer. This function was introduced in Qt 5.0. void QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069mousePress(QWidget *widget, Qt8b7c:f320:99b9:690f:4595:cd17:293a:c069MouseButton button, Qt8b7c:f320:99b9:690f:4595:cd17:293a:c069KeyboardModifiers modifier = ..., QPoint pos = ..., int delay = ...) Simulates pressing a mouse button with an optional modifier on a widget. The position is defined by pos; the default position is the center of the widget. If delay is specified, the test will wait for the specified amount of milliseconds before the press. See also QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069mouseRelease() and QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069mouseClick(). void QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069mousePress(QWindow *window, Qt8b7c:f320:99b9:690f:4595:cd17:293a:c069MouseButton button, Qt8b7c:f320:99b9:690f:4595:cd17:293a:c069KeyboardModifiers stateKey = ..., QPoint pos = ..., int delay = ...) This is an overloaded function. Simulates pressing a mouse button with an optional stateKey modifier on a window. The position is defined by pos; the default position is the center of the window. If delay is specified, the test will wait for the specified amount of milliseconds before the press. This function was introduced in Qt 5.0. See also QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069mouseRelease() and QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069mouseClick(). void QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069mouseRelease(QWidget *widget, Qt8b7c:f320:99b9:690f:4595:cd17:293a:c069MouseButton button, Qt8b7c:f320:99b9:690f:4595:cd17:293a:c069KeyboardModifiers modifier = ..., QPoint pos = ..., int delay = ...) Simulates releasing a mouse button with an optional modifier on a widget. The position of the release is defined by pos; the default position is the center of the widget. If delay is specified, the test will wait for the specified amount of milliseconds before releasing the button. See also QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069mousePress() and QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069mouseClick(). void QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069mouseRelease(QWindow *window, Qt8b7c:f320:99b9:690f:4595:cd17:293a:c069MouseButton button, Qt8b7c:f320:99b9:690f:4595:cd17:293a:c069KeyboardModifiers stateKey = ..., QPoint pos = ..., int delay = ...) This is an overloaded function. Simulates releasing a mouse button with an optional stateKey modifier on a window. The position of the release is defined by pos; the default position is the center of the window. If delay is specified, the test will wait for the specified amount of milliseconds before releasing the button. This function was introduced in Qt 5.0. See also QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069mousePress() and QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069mouseClick(). QTestData &QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069newRow(const char *dataTag) Appends a new row to the current test data. dataTag is the name of the testdata that will appear in the test output. Returns a QTestData reference that can be used to stream in data. Example: void myTestFunction_data() { QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069olumn<QString>("aString"); QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069newRow("just hello") << QString("hello"); QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069newRow("a null string") << QString(); } Note: This macro can only be used in a test's data function that is invoked by the test framework. See Data Driven Testing for a more extensive example. See also addColumn() and QFETCH(). int QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069qExec(QObject *testObject, int argc = 0, char **argv = nullptr) Executes tests declared in testObject. In addition, the private slots initTestCase(), cleanupTestCase(), init() and cleanup() are executed if they exist. See Creating a Test for more details. Optionally, the command line arguments argc and argv can be provided. For a list of recognized arguments, read Qt Test Command Line Arguments. The following example will run all tests in MyTestObject: MyTestObject test1; QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069qExec(&test1); This function returns 0 if no tests failed, or a value other than 0 if one or more tests failed or in case of unhandled exceptions. (Skipped tests do not influence the return value.) For stand-alone test applications, the convenience macro QTEST_MAIN() can be used to declare a main() function that parses the command line arguments and executes the tests, avoiding the need to call this function explicitly. The return value from this function is also the exit code of the test application when the QTEST_MAIN() macro is used. For stand-alone test applications, this function should not be called more than once, as command-line options for logging test output to files and executing individual test functions will not behave correctly. Note: This function is not reentrant, only one test can run at a time. A test that was executed with qExec() can't run another test via qExec() and threads are not allowed to call qExec() simultaneously. If you have programatically created the arguments, as opposed to getting them from the arguments in main(), it is likely of interest to use QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069qExec(QObject *, const QStringList &) since it is Unicode safe. See also QTEST_MAIN(). int QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069qExec(QObject *testObject, const QStringList &arguments) This is an overloaded function. Behaves identically to qExec(QObject *, int, char**) but takes a QStringList of arguments instead of a char** list. This function was introduced in Qt 4.4. QSharedPointer<QTemporaryDir> QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069qExtractTestData(const QString &dirName) Extracts a directory from resources to disk. The content is extracted recursively to a temporary folder. The extracted content is removed automatically once the last reference to the return value goes out of scope. dirName is the name of the directory to extract from resources. Returns the temporary directory where the data was extracted or null in case of errors. void QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069qSleep(int ms) Sleeps for ms milliseconds, blocking execution of the test. qSleep() will not do any event processing and leave your test unresponsive. Network communication might time out while sleeping. Use QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069qWait() to do non-blocking sleeping. ms must be greater than 0. Note: The qSleep() function calls either nanosleep() on unix or Sleep() on windows, so the accuracy of time spent in qSleep() depends on the operating system. Example: QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069qSleep(250); See also QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069qWait(). void QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069qWait(int ms) Waits for ms milliseconds. While waiting, events will be processed and your test will stay responsive to user interface events or network communication. Example: int i = 0; while (myNetworkServerNotResponding() && i++ < 50) QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069qWait(250); The code above will wait until the network server is responding for a maximum of about 12.5 seconds. See also QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069qSleep() and QSignalSpy8b7c:f320:99b9:690f:4595:cd17:293a:c069wait(). bool QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069qWaitFor(Functor predicate, int timeout = 5000) Waits for timeout milliseconds or until the predicate returns true. Returns true if the predicate returned true at any point, otherwise returns false. Example: MyObject obj; obj.startup(); QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069qWaitFor([&]() { return obj.isReady(); }, 3000); The code above will wait for the object to become ready, for a maximum of three seconds. This function was introduced in Qt 5.10. bool QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069qWaitForWindowActive(QWindow *window, int timeout = 5000) Waits for timeout milliseconds or until the window is active. Returns true if window is active within timeout milliseconds, otherwise returns false. This function was introduced in Qt 5.0. See also qWaitForWindowExposed() and QWindow8b7c:f320:99b9:690f:4595:cd17:293a:c069isActive(). bool QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069qWaitForWindowActive(QWidget *widget, int timeout = 5000) Waits for timeout milliseconds or until the widget's window is active. Returns true if widget's window is active within timeout milliseconds, otherwise returns false. This function was introduced in Qt 5.0. See also qWaitForWindowExposed() and QWidget8b7c:f320:99b9:690f:4595:cd17:293a:c069isActiveWindow(). bool QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069qWaitForWindowExposed(QWindow *window, int timeout = 5000) Waits for timeout milliseconds or until the window is exposed. Returns true if window is exposed within timeout milliseconds, otherwise returns false. This is mainly useful for asynchronous systems like X11, where a window will be mapped to screen some time after being asked to show itself on the screen. Note that a window that is mapped to screen may still not be considered exposed if the window client area is completely covered by other windows, or if the window is otherwise not visible. This function will then time out when waiting for such a window. This function was introduced in Qt 5.0. See also qWaitForWindowActive() and QWindow8b7c:f320:99b9:690f:4595:cd17:293a:c069isExposed(). bool QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069qWaitForWindowExposed(QWidget *widget, int timeout = 5000) Waits for timeout milliseconds or until the widget's window is exposed. Returns true if widget's window is exposed within timeout milliseconds, otherwise returns false. This is mainly useful for asynchronous systems like X11, where a window will be mapped to screen some time after being asked to show itself on the screen. Note that a window that is mapped to screen may still not be considered exposed if the window client area is completely covered by other windows, or if the window is otherwise not visible. This function will then time out when waiting for such a window. A specific configuration where this happens is when using QGLWidget as a viewport widget on macOS: The viewport widget gets the expose event, not the parent widget. This function was introduced in Qt 5.0. See also qWaitForWindowActive(). void QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069setBenchmarkResult(qreal result, QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069QBenchmarkMetric metric) Sets the benchmark result for this test function to result. Use this function if you want to report benchmark results without using the QBENCHMARK macro. Use metric to specify how Qt Test should interpret the results. The context for the result will be the test function name and any data tag from the _data function. This function can only be called once in each test function, subsequent calls will replace the earlier reported results. Note that the -iterations command line argument has no effect on test functions without the QBENCHMARK macro. This function was introduced in Qt 4.7. char *QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069toHexRepresentation(const char *ba, int length) Returns a pointer to a string that is the string ba represented as a space-separated sequence of hex characters. If the input is considered too long, it is truncated. A trucation is indicated in the returned string as an ellipsis at the end. The caller has ownership of the returned pointer and must ensure it is later passed to operator delete[]. length is the length of the string ba. char *QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069toString(const T &value) Returns a textual representation of value. This function is used by QCOMPARE() to output verbose information in case of a test failure. You can add specializations or overloads of this function to your test to enable verbose output. Note: Starting with Qt 5.5, you should prefer to provide a toString() function in the type's namespace instead of specializing this template. If your code needs to continue to work with the QTestLib from Qt 5.4 or earlier, you need to continue to use specialization. Note: The caller of toString() must delete the returned data using delete[]. Your implementation should return a string created with new[] or qstrdup(). The easiest way to do so is to create a QByteArray or QString and calling QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069toString() on it (see second example below). Example for specializing (Qt ≤ 5.4): namespace QTest { template<> char *toString(const MyPoint &point) { QByteArray ba = "MyPoint("; ba += QByteArray8b7c:f320:99b9:690f:4595:cd17:293a:c069number(point.x()) + ", " + QByteArray8b7c:f320:99b9:690f:4595:cd17:293a:c069number(point.y()); ba += ')'; return qstrdup(ba.data()); } } The example above defines a toString() specialization for a class called MyPoint. Whenever a comparison of two instances of MyPoint fails, QCOMPARE() will call this function to output the contents of MyPoint to the test log. Same example, but with overloading (Qt ≥ 5.5): namespace MyNamespace { char *toString(const MyPoint &point) { // bring QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069toString overloads into scope: using QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069toString; // delegate char* handling to QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069toString(QByteArray): return toString("MyPoint(" + QByteArray8b7c:f320:99b9:690f:4595:cd17:293a:c069number(point.x()) + ", " + QByteArray8b7c:f320:99b9:690f:4595:cd17:293a:c069number(point.y()) + ')'); } } See also QCOMPARE(). char *QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069toString(const QPair<T1, T2> &pair) This is an overloaded function. Returns a textual representation of the pair. This function was introduced in Qt 5.11. char *QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069toString(QSizePolicy8b7c:f320:99b9:690f:4595:cd17:293a:c069ontrolTypes cts) This is an overloaded function. Returns a textual representation of control types cts. This function was introduced in Qt 5.5. char *QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069toString(QSizePolicy8b7c:f320:99b9:690f:4595:cd17:293a:c069ontrolType ct) This is an overloaded function. Returns a textual representation of control type ct. This function was introduced in Qt 5.5. char *QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069toString(QSizePolicy sp) This is an overloaded function. Returns a textual representation of size policy sp. This function was introduced in Qt 5.5. char *QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069toString(const st8b7c:f320:99b9:690f:4595:cd17:293a:c069pair<T1, T2> &pair) This is an overloaded function. Returns a textual representation of the pair. This function was introduced in Qt 5.11. char *QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069toString(const st8b7c:f320:99b9:690f:4595:cd17:293a:c069tuple<Types...> &tuple) This is an overloaded function. Returns a textual representation of the given tuple. This function was introduced in Qt 5.12. char *QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069toString(const QStringView &string) This is an overloaded function. Returns a textual representation of the given string. This function was introduced in Qt 5.11. char *QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069toString(const QString &string) This is an overloaded function. Returns a textual representation of the given string. char *QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069toString(const QLatin1String &string) This is an overloaded function. Returns a textual representation of the given string. char *QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069toString(const QByteArray &ba) This is an overloaded function. Returns a textual representation of the byte array ba. See also QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069toHexRepresentation(). char *QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069toString(const QTime &time) This is an overloaded function. Returns a textual representation of the given time. char *QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069toString(const QDate &date) This is an overloaded function. Returns a textual representation of the given date. char *QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069toString(const QDateTime &dateTime) This is an overloaded function. Returns a textual representation of the date and time specified by dateTime. char *QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069toString(const QCborError &c) This is an overloaded function. Returns a textual representation of the given CBOR error c. This function was introduced in Qt 5.12. char *QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069toString(const QChar &character) This is an overloaded function. Returns a textual representation of the given character. char *QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069toString(const QPoint &point) This is an overloaded function. Returns a textual representation of the given point. char *QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069toString(const QSize &size) This is an overloaded function. Returns a textual representation of the given size. char *QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069toString(const QRect &rectangle) This is an overloaded function. Returns a textual representation of the given rectangle. char *QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069toString(const QPointF &point) This is an overloaded function. Returns a textual representation of the given point. char *QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069toString(const QSizeF &size) This is an overloaded function. Returns a textual representation of the given size. char *QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069toString(const QRectF &rectangle) This is an overloaded function. Returns a textual representation of the given rectangle. char *QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069toString(const QUrl &url) This is an overloaded function. Returns a textual representation of the given url. This function was introduced in Qt 4.4. char *QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069toString(const QUuid &uuid) This is an overloaded function. Returns a textual representation of the given uuid. This function was introduced in Qt 5.11. char *QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069toString(const QVariant &variant) This is an overloaded function. Returns a textual representation of the given variant. char *QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069toString(st8b7c:f320:99b9:690f:4595:cd17:293a:c069nullptr_t) This is an overloaded function. Returns a string containing nullptr. This function was introduced in Qt 5.8. char *QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069toString(const QVector2D &v) This is an overloaded function. Returns a textual representation of the 2D vector v. This function was introduced in Qt 5.11. char *QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069toString(const QVector3D &v) This is an overloaded function. Returns a textual representation of the 3D vector v. This function was introduced in Qt 5.11. char *QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069toString(const QVector4D &v) This is an overloaded function. Returns a textual representation of the 4D vector v. This function was introduced in Qt 5.11. char *QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069toString(QSizePolicy8b7c:f320:99b9:690f:4595:cd17:293a:c069Policy p) This is an overloaded function. Returns a textual representation of policy p. This function was introduced in Qt 5.5. QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069QTouchEventSequence QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069touchEvent(QWidget *widget, QTouchDevice *device, bool autoCommit) Creates and returns a QTouchEventSequence for the device to simulate events for widget. When adding touch events to the sequence, widget will also be used to translate the position provided to screen coordinates, unless another widget is provided in the respective calls to press(), move() etc. The touch events are committed to the event system when the destructor of the QTouchEventSequence is called (ie when the object returned runs out of scope), unless autoCommit is set to false. When autoCommit is false, commit() has to be called manually. QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069QTouchEventSequence QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069touchEvent(QWindow *window, QTouchDevice *device, bool autoCommit) Creates and returns a QTouchEventSequence for the device to simulate events for window. When adding touch events to the sequence, window will also be used to translate the position provided to screen coordinates, unless another window is provided in the respective calls to press(), move() etc. The touch events are committed to the event system when the destructor of the QTouchEventSequence is called (ie when the object returned runs out of scope), unless autoCommit is set to false. When autoCommit is false, commit() has to be called manually. This function was introduced in Qt 5.0. Macro Documentation QBENCHMARK This macro is used to measure the performance of code within a test. The code to be benchmarked is contained within a code block following this macro. For example: void TestBenchmark8b7c:f320:99b9:690f:4595:cd17:293a:c069simple() { QString str1 = QLatin1String("This is a test string"); QString str2 = QLatin1String("This is a test string"); QCOMPARE(str1.localeAwareCompare(str2), 0); QBENCHMARK { str1.localeAwareCompare(str2); } } See also Creating a Benchmark and Writing a Benchmark. QBENCHMARK_ONCE The QBENCHMARK_ONCE macro is for measuring performance of a code block by running it once. This macro is used to measure the performance of code within a test. The code to be benchmarked is contained within a code block following this macro. Unlike QBENCHMARK, the contents of the contained code block is only run once. The elapsed time will be reported as "0" if it's to short to be measured by the selected backend. (Use) This function was introduced in Qt 4.6. See also Creating a Benchmark and Writing a Benchmark. QCOMPARE(actual, expected) The QCOMPARE() macro compares an actual value to an expected value using the equality operator. If actual and expected match, execution continues. If not, a failure is recorded in the test log and the test function returns without attempting any later checks. Always respect QCOMPARE() parameter semantics. The first parameter passed to it should always be the actual value produced by the code-under-test, while the second parameter should always be the expected value. When the values don't match, QCOMPARE() prints them with the labels Actual and Expected. If the parameter order is swapped, debugging a failing test can be confusing. When comparing floating-point types (float, double, and qfloat16), qFuzzyCompare() is used for finite values. Infinities match if they have the same sign, and any NaN as actual value matches with any NaN as expected value (even though NaN != NaN, even when they're identical). This means that expecting 0 can fail when the actual value may be affected by rounding errors. One solution to this is to offset both actual and expected values by adding some suitable constant (such as 1). QCOMPARE() tries to output the contents of the values if the comparison fails, so it is visible from the test log why the comparison failed. Example: QCOMPARE(QString("hello").toUpper(), QString("HELLO")); Note: This macro can only be used in a test function that is invoked by the test framework. For your own classes, you can use QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069toString() to format values for outputting into the test log. Example: namespace QTest { template <> char *toString<MyType>(const MyType &t) { char *repr = new char[t.reprSize()]; t.writeRepr(repr); return repr; } } The return from toString() must be a new char []. That is, it shall be released with delete[] (rather than free() or plain delete) once the calling code is done with it. See also QVERIFY(), QTRY_COMPARE(), QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069toString(), and QEXPECT_FAIL(). QEXPECT_FAIL(dataIndex, comment, mode) The QEXPECT_FAIL() macro marks the next QCOMPARE() or QVERIFY() as an expected failure. Instead of adding a failure to the test log, an expected failure will be reported. If a QVERIFY() or QCOMPARE() is marked as an expected failure, but passes instead, an unexpected pass (XPASS) is written to the test log. The parameter dataIndex describes for which entry in the test data the failure is expected. Pass an empty string ("") if the failure is expected for all entries or if no test data exists. comment will be appended to the test log for the expected failure. mode is a QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069TestFailMode and sets whether the test should continue to execute or not. Note: This macro can only be used in a test function that is invoked by the test framework. Example 1: QEXPECT_FAIL("", "Will fix in the next release", Continue); QCOMPARE(i, 42); QCOMPARE(j, 43); In the example above, an expected fail will be written into the test output if the variable i is not 42. If the variable i is 42, an unexpected pass is written instead. The QEXPECT_FAIL() has no influence on the second QCOMPARE() statement in the example. Example 2: QEXPECT_FAIL("data27", "Oh my, this is soooo broken", Abort); QCOMPARE(i, 42); The above testfunction will not continue executing for the test data entry data27. See also QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069TestFailMode, QVERIFY(), and QCOMPARE(). QFAIL(message) This macro can be used to force a test failure. The test stops executing and the failure message is appended to the test log. Note: This macro can only be used in a test function that is invoked by the test framework. Example: if (sizeof(int) != 4) QFAIL("This test has not been ported to this platform yet."); QFETCH(type, name) The fetch macro creates a local variable named name with the type type on the stack. The name and type must match a column from the test's data table. This is asserted and the test will abort if the assertion fails. Assuming a test has the following data: void TestQString8b7c:f320:99b9:690f:4595:cd17:293a:c069toInt_data() { QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069olumn<QString>("aString"); QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069olumn<int>("expected"); QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069newRow("positive value") << "42" << 42; QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069newRow("negative value") << "-42" << -42; QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069newRow("zero") << "0" << 0; } The test data has two elements, a QString called aString and an integer called expected. To fetch these values in the actual test: void TestQString8b7c:f320:99b9:690f:4595:cd17:293a:c069toInt() { QFETCH(QString, aString); QFETCH(int, expected); QCOMPARE(aString.toInt(), expected); } aString and expected are variables on the stack that are initialized with the current test data. Note: This macro can only be used in a test function that is invoked by the test framework. The test function must have a _data function. QFETCH_GLOBAL(type, name) This macro fetches a variable named name with the type type from a row in the global data table. The name and type must match a column in the global data table. This is asserted and the test will abort if the assertion fails. Assuming a test has the following data: void TestQLocal8b7c:f320:99b9:690f:4595:cd17:293a:c069initTestCase_data() { QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069olumn<QLocale>("locale"); QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069newRow("C") << QLocal8b7c:f320:99b9:690f:4595:cd17:293a:c069c(); QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069newRow("UKish") << QLocale("en_GB"); QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069newRow("USAish") << QLocale(QLocal8b7c:f320:99b9:690f:4595:cd17:293a:c069English); } void TestQLocal8b7c:f320:99b9:690f:4595:cd17:293a:c069roundTripInt_data() { QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069olumn<int>("number"); QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069newRow("one") << 1; QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069newRow("two") << 2; QTest8b7c:f320:99b9:690f:4595:cd17:293a:c069newRow("ten") << 10; } The test's own data is a single number per row. In this case, initTestCase_data() also supplies a locale per row. Therefore, this test will be run with every combination of locale from the latter and number from the former. void TestQLocal8b7c:f320:99b9:690f:4595:cd17:293a:c069roundTripInt() { QFETCH_GLOBAL(QLocale, locale); QFETCH(int, number); bool ok; QCOMPARE(locale.toInt(locale.toString(number), &ok), number); QVERIFY(ok); } The locale is read from the global data table using QFETCH_GLOBAL(), and the number is read from the local data table using QFETCH(). Note: This macro can only be used in test methods of a class with an initTestCase_data() method. QFINDTESTDATA(filename) Returns a QString for the testdata file referred to by filename, or an empty QString if the testdata file could not be found. This macro allows the test to load data from an external file without hardcoding an absolute filename into the test, or using relative paths which may be error prone. The returned path will be the first path from the following list which resolves to an existing file or directory: filename relative to QCoreApplication8b7c:f320:99b9:690f:4595:cd17:293a:c069pplicationDirPath() (only if a QCoreApplication or QApplication object has been created). filename relative to the test's standard install directory (QLibraryInfo8b7c:f320:99b9:690f:4595:cd17:293a:c069TestsPath with the lowercased testcase name appended). filename relative to the directory containing the source file from which QFINDTESTDATA is invoked. If the named file/directory does not exist at any of these locations, a warning is printed to the test log. For example, in this code: // Source: /home/user/sources/myxmlparser/tests/tst_myxmlparser/tst_myxmlparser.cpp // Build: /home/user/build/myxmlparser/tests/tst_myxmlparser // Qt: /usr/local/Qt-5.0.0 void tst_MyXmlParser8b7c:f320:99b9:690f:4595:cd17:293a:c069parse() { MyXmlParser parser; QString input = QFINDTESTDATA("testxml/simple1.xml"); QVERIFY(parser.parse(input)); } The testdata file will be resolved as the first existing file from: /home/user/build/myxmlparser/tests/tst_myxmlparser/testxml/simple1.xml /usr/local/Qt-5.0.0/tests/tst_myxmlparser/testxml/simple1.xml /home/user/sources/myxmlparser/tests/tst_myxmlparser/testxml/simple1.xml This allows the test to find its testdata regardless of whether the test has been installed, and regardless of whether the test's build tree is equal to the test's source tree. Note: reliable detection of testdata from the source directory requires either that qmake is used, or the QT_TESTCASE_BUILDDIR macro is defined to point to the working directory from which the compiler is invoked, or only absolute paths to the source files are passed to the compiler. Otherwise, the absolute path of the source directory cannot be determined. Note: For tests that use the QTEST_APPLESS_MAIN() macro to generate a main() function, QFINDTESTDATA will not attempt to find test data relative to QCoreApplication8b7c:f320:99b9:690f:4595:cd17:293a:c069pplicationDirPath(). In practice, this means that tests using QTEST_APPLESS_MAIN() will fail to find their test data if run from a shadow build tree. This function was introduced in Qt 5.0. QSKIP(description) If called from a test function, the QSKIP() macro stops execution of the test without adding a failure to the test log. You can use it to skip tests that wouldn't make sense in the current configuration. For example, a test of font rendering may call QSKIP() if the needed fonts are not installed on the test system. The text description is appended to the test log and should contain an explanation of why the test couldn't be executed. If the test is data-driven, each call to QSKIP() in the test function will skip only the current row of test data, so an unconditional call to QSKIP() will produce one skip message in the test log for each row of test data. If called from an _data function, the QSKIP() macro will stop execution of the _data function and will prevent execution of the associated test function. This entirely omits a data-driven test. To omit individual rows, make them conditional by using a simple if (condition) newRow(...) << ... in the _data function, instead of using QSKIP() in the test function. If called from initTestCase_data(), the QSKIP() macro will skip all test and _data functions. If called from initTestCase() when there is no initTestCase_data(), or when it only sets up one row, QSKIP() will likewise skip the whole test. However, if initTestCase_data() contains more than one row, then initTestCase() is called (followed by each test and finally the wrap-up) once per row of it. Therefore, a call to QSKIP() in initTestCase() will merely skip all test functions for the current row of global data, set up by initTestCase_data(). Note: This macro can only be used in a test function or _data function that is invoked by the test framework. Example: if (!QSqlDatabas8b7c:f320:99b9:690f:4595:cd17:293a:c069drivers().contains("SQLITE")) QSKIP("This test requires the SQLITE database driver"); Skipping Known Bugs If a test exposes a known bug that will not be fixed immediately, use the QEXPECT_FAIL() macro to document the failure and reference the bug tracking identifier for the known issue. When the test is run, expected failures will be marked as XFAIL in the test output and will not be counted as failures when setting the test program's return code. If an expected failure does not occur, the XPASS (unexpected pass) will be reported in the test output and will be counted as a test failure. For known bugs, QEXPECT_FAIL() is better than QSKIP() because a developer cannot fix the bug without an XPASS result reminding them that the test needs to be updated too. If QSKIP() is used, there is no reminder to revise or re-enable the test, without which subsequent regressions will not be reported. See also QEXPECT_FAIL() and Select Appropriate Mechanisms to Exclude Tests. QTEST(actual, testElement) QTEST() is a convenience macro for QCOMPARE() that compares the value actual with the element testElement from the test's data. If there is no such element, the test asserts. Apart from that, QTEST() behaves exactly as QCOMPARE(). Instead of writing: QFETCH(QString, myString); QCOMPARE(QString("hello").toUpper(), myString); you can write: QTEST(QString("hello").toUpper(), "myString"); See also QCOMPARE(). QTEST_APPLESS_MAIN(TestClass) Implements a main() function that executes all tests in TestClass. Behaves like QTEST_MAIN(), but doesn't instantiate a QApplication object. Use this macro for really simple stand-alone non-GUI tests. See also QTEST_MAIN(). QTEST_GUILESS_MAIN(TestClass) Implements a main() function that instantiates a QCoreApplication object and the TestClass, and executes all tests in the order they were defined. Use this macro to build stand-alone executables. Behaves like QTEST_MAIN(), but instantiates a QCoreApplication instead of the QApplication object. Use this macro if your test case doesn't need functionality offered by QApplication, but the event loop is still necessary. This function was introduced in Qt 5.0. See also QTEST_MAIN(). QTEST_MAIN(TestClass) Implements a main() function that instantiates an application object and the TestClass, and executes all tests in the order they were defined. Use this macro to build stand-alone executables. If QT_WIDGETS_LIB is defined, the application object will be a QApplication, if QT_GUI_LIB is defined, the application object will be a QGuiApplication, otherwise it will be a QCoreApplication. If qmake is used and the configuration includes QT += widgets, then QT_WIDGETS_LIB will be defined automatically. Similarly, if qmake is used and the configuration includes QT += gui, then QT_GUI_LIB will be defined automatically. Note: On platforms that have keypad navigation enabled by default, this macro will forcefully disable it if QT_WIDGETS_LIB is defined. This is done to simplify the usage of key events when writing autotests. If you wish to write a test case that uses keypad navigation, you should enable it
{'path': 'public/docs/qt~5.14/qtest.html', 'source': 'DevDocs.IO'}