diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index b30425b7e8637b7efedfba6facf00e714cc38cb6..14f3043df7fc79c2ee228e44a8fb394627f33b21 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -1,4 +1,4 @@
-find_package(Qt${QT_VERSION_MAJOR} CONFIG REQUIRED QuickTest Widgets Test)
+find_package(Qt${QT_VERSION_MAJOR} CONFIG REQUIRED QuickTest Test Widgets)
 
 if(MSVC)
     # Download and unpack googletest for windows
@@ -15,7 +15,7 @@ else()
 endif()
 
 enable_testing(true)
-set(QML_TEST_LIBS ${QML_LIBS} Qt::QuickTest Qt::Widgets Qt::Test)
+set(QML_TEST_LIBS ${QT_LIBS} Qt::QuickTest Qt::Test Qt::Widgets)
 set(TESTS_INCLUDES
     ${CMAKE_SOURCE_DIR}/src
     ${CMAKE_SOURCE_DIR}/tests/qml
diff --git a/tests/qml/main.cpp b/tests/qml/main.cpp
index 09c02f3e1dbcced3bef5326dac388d07682d64f6..4c42027c79abfb727231f264ae8a7963a8193639 100644
--- a/tests/qml/main.cpp
+++ b/tests/qml/main.cpp
@@ -31,9 +31,10 @@
 #include <QQmlEngine>
 #include <QQmlContext>
 #include <QFontDatabase>
+#ifdef WITH_WEBENGINE
 #include <QtWebEngineCore>
 #include <QtWebEngineQuick>
-
+#endif
 #ifdef Q_OS_WIN
 #include <windows.h>
 #endif
@@ -155,9 +156,9 @@ main(int argc, char** argv)
         // Adjust the argument count.
         argc = std::distance(argv, end);
     }
-
+#ifdef WITH_WEBENGINE
     QtWebEngineQuick::initialize();
-
+#endif
     QTEST_SET_MAIN_SOURCE_PATH
     Setup setup(muteDring);
     return quick_test_main_with_setup(argc, argv, "qml_test", nullptr, &setup);