QTest: Failing to use QUICK_TEST_MAIN_WITH_SETUP
-
I'm using Qt5.11.2 and I want to use the new QUICK_TEST_MAIN_WITH_SETUP macro. The Setup object is constructed but the slot is never called so I guess I'm doing something wrong.
When usingQML_IMPORT_TRACE=1
, I don't see my newly-added import paths either.
Any ideas?I have the following main.cpp (similar to the example on https://doc.qt.io/qt-5.11/qtquicktest-index.html#executing-c-before-qml-tests except for the
#include "tst_mytest.moc"
at the end since it is unclear to which moc file it refers)#include <QtQuickTest> #include <QQmlEngine> #include <QQmlContext> class Setup : public QObject { public: Setup() { qDebug() << "***Setup"; } public slots: void qmlEngineAvailable(QQmlEngine *engine) { qDebug() << "***qmlEngineAvailable"; engine->addImportPath("blablabla"); } }; QUICK_TEST_MAIN_WITH_SETUP(example, Setup)
-
I guess there is a missing Q_OBJECT macro in the example Setup class in https://doc.qt.io/qt-5.11/qtquicktest-index.html#executing-c-before-qml-tests
, right?
Is it possible to provide a minimal example illustrating that qmlEngineAvailable gets called? -
Adding Q_OBJECT and #include "main.moc" at the end solved this issue