Divide a QTest into implementation and header file
-
Hi all,
I've a very simple question: I want to divide a test into an implementation and header file like this:
#include "tst_simpletest.hpp" void simpleTest::test_case1() { } QTEST_APPLESS_MAIN(simpleTest) #include "tst_simpletest.moc"#ifndef TST_SIMPLETEST_HPP #define TST_SIMPLETEST_HPP #include <QtTest> // add necessary includes here class simpleTest : public QObject { Q_OBJECT public: private slots: void test_case1(); }; #endif // TST_SIMPLETEST_HPPcmake_minimum_required(VERSION 3.5) project(simpleTest LANGUAGES CXX) enable_testing() find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Test) find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Test) set(CMAKE_AUTOUIC ON) set(CMAKE_AUTOMOC ON) set(CMAKE_AUTORCC ON) set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD_REQUIRED ON) add_executable(simpleTest tst_simpletest.cpp tst_simpletest.hpp) add_test(NAME simpleTest COMMAND simpleTest) target_link_libraries(simpleTest PRIVATE Qt${QT_VERSION_MAJOR}::Test)Quite simple but I got a warning during compilation:
[1/4 0.4/sec] Automatic MOC and UIC for target simpleTest AutoMoc warning --------------- "SRC:/tst_simpletest.cpp" includes the moc file "tst_simpletest.moc", but does not contain a Q_OBJECT, Q_GADGET, Q_GADGET_EXPORT, Q_NAMESPACE or Q_NAMESPACE_EXPORT macro. AutoMoc: /home/mario/qtTestTest/tst_simpletest.cpp:0:1: note: No relevant classes found. No output generated. [2/4 0.3/sec] Building CXX object CMakeFiles/simpleTest.dir/simpleTest_autogen/mocs_compilation.cpp.o [3/4 0.4/sec] Building CXX object CMakeFiles/simpleTest.dir/tst_simpletest.cpp.o [4/4 0.5/sec] Linking CXX executable simpleTest 09:14:06: The process "/usr/bin/cmake" exited normally. 09:14:06: Elapsed time: 00:08.How can I fix this warning?
I can remove the moc include and the build is successful, the test ist running but isn't the content of the moc file missing? Or is this inlcude remnant of qmake and done with the CMAKE_AUTOMOC step?
Best Fred
-
You don't need the moc include because you now have a header where cmake can find the class declaration and can create the moc file automatically
-
-
You don't need the moc include because you now have a header where cmake can find the class declaration and can create the moc file automatically
-
F FredJupiter has marked this topic as solved on