Moc not invoked



  • Hi

    If I declare a class in a cpp file -
    @
    #include <QObject>

    class NewTest : public QObject
    {
    Q_OBJECT

    private slots:
    void s1();
    };

    void NewTest::s1()
    {

    }

    #include "NewTest.moc"
    @

    The moc compiler is not invoked
    However, if I declare a constructor for NewTest it is

    Can anyone explain why this is?

    I am writing some unit tests and do not need the constructor.

    Once the moc has been invoked I can remove the constructor and then everything works as expected

    Thanks



  • Hi,

    Qt Objects needs a constructor where you declare a parent object;

    Anyway I suggest to follow the rules:

    [C++] Declare classes in .H files

    [Qt] If you inherits from QObject and want use Q_OBJECT macro, declare at least a constructor that accept a QObject*

    If you're writing QTestLib unit tests, your code is correct but you missed to insert
    @
    QTEST_MAIN(NewTest)
    @

    before include moc file


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.