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. Moc not invoked
Forum Updated to NodeBB v4.3 + New Features

Moc not invoked

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 593 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.
  • G Offline
    G Offline
    GrahamL
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mcosta
      wrote on last edited by
      #2

      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

      Once your problem is solved don't forget to:

      • Mark the thread as SOLVED using the Topic Tool menu
      • Vote up the answer(s) that helped you to solve the issue

      You can embed images using (http://imgur.com/) or (http://postimage.org/)

      1 Reply Last reply
      0

      • Login

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