Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Divide a QTest into implementation and header file
Forum Updated to NodeBB v4.3 + New Features

Divide a QTest into implementation and header file

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 3 Posters 284 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    FredJupiter
    wrote on last edited by FredJupiter
    #1

    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_HPP
    
    cmake_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

    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #3

      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

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      2
      • aha_1980A Offline
        aha_1980A Offline
        aha_1980
        Lifetime Qt Champion
        wrote on last edited by
        #2

        Does https://stackoverflow.com/questions/34928933/why-is-important-to-include-moc-file-at-end-of-a-qt-source-code-file answer your question?

        Qt has to stay free or it will die.

        1 Reply Last reply
        1
        • Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #3

          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

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          1 Reply Last reply
          2
          • F FredJupiter has marked this topic as solved on

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved