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. when should Generating "moc" files in qt project,and what is the "moc" files's function?
Forum Updated to NodeBB v4.3 + New Features

when should Generating "moc" files in qt project,and what is the "moc" files's function?

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 4 Posters 2.0k Views 2 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.
  • P Offline
    P Offline
    Princein
    wrote on last edited by
    #1

    I create a new qt project in Mac qt for test the example in :http://doc.qt.io/archives/qt-4.8/signalsandslots.html#signals-and-slots
    for test the 'Signals & Slots', it seem it will generated moc_counter.cpp.o,moc_predefs.h,moc_counter.o "moc" files in the "-Deubg" directory after build,I delete the "moc" files,and I run the project again,everything is work right,
    in my main.cpp,here is the code copy from the example in :http://doc.qt.io/archives/qt-4.8/signalsandslots.html#signals-and-slots
    Counter a,b;
    QObject::connect(&a, SIGNAL(valueChanged(int)),
    &b, SLOT(setValue(int)));
    a.setValue(12);
    cout << "1" + string("a的值") + to_string(a.value()) + " b的值" + to_string(b.value()) << endl;
    b.setValue(48);
    cout << "2" + string("a的值") + to_string(a.value()) + " b的值" + to_string(b.value()) << endl;
    after delete the "moc" files in "-Deubg" directory,I run the project again,I can still get right answer,

    what dose the "moc" files do,and when I need Generating "moc" files,and when should I add the Generating "moc" files to my project to use them?

    in my another qt project,when I run the project,it shows me error"QMetaObject::connectSlotsByName: No matching signal for "
    is it because I lack the "moc" files?

    thanks a lot!

    K 1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      moc files are generated by moc tool (Meta Object Compiler) - they are always generated for all QObject classes. They are absolutely required for meta stuff to work, so things like:

      • signals
      • slots
      • Q_INVOKABLE
      • QMeta* classes

      However, these files are generated at build time. You don't need to keep them in your project, same as you don't need to store Makefiles, object files etc.
      Actually, I strongly recommend building your code outside of your source code directory. Qt Creator does this automatically (it's called a "shadow build").

      Other code generators in Qt include:

      • uic (generates UI headers from .ui files)
      • rcc (generates cpp resource files from .qrc files)
      • lupdate/lrelease (for translations)

      (Z(:^

      P 1 Reply Last reply
      7
      • P Princein

        I create a new qt project in Mac qt for test the example in :http://doc.qt.io/archives/qt-4.8/signalsandslots.html#signals-and-slots
        for test the 'Signals & Slots', it seem it will generated moc_counter.cpp.o,moc_predefs.h,moc_counter.o "moc" files in the "-Deubg" directory after build,I delete the "moc" files,and I run the project again,everything is work right,
        in my main.cpp,here is the code copy from the example in :http://doc.qt.io/archives/qt-4.8/signalsandslots.html#signals-and-slots
        Counter a,b;
        QObject::connect(&a, SIGNAL(valueChanged(int)),
        &b, SLOT(setValue(int)));
        a.setValue(12);
        cout << "1" + string("a的值") + to_string(a.value()) + " b的值" + to_string(b.value()) << endl;
        b.setValue(48);
        cout << "2" + string("a的值") + to_string(a.value()) + " b的值" + to_string(b.value()) << endl;
        after delete the "moc" files in "-Deubg" directory,I run the project again,I can still get right answer,

        what dose the "moc" files do,and when I need Generating "moc" files,and when should I add the Generating "moc" files to my project to use them?

        in my another qt project,when I run the project,it shows me error"QMetaObject::connectSlotsByName: No matching signal for "
        is it because I lack the "moc" files?

        thanks a lot!

        K Offline
        K Offline
        kenchan
        wrote on last edited by
        #3

        @Princein
        the moc files are generated automatically here are a couple of documents links so you can read about them.
        http://doc.qt.io/archives/qt-4.8/moc.html
        http://doc.qt.io/qt-5/why-moc.html

        1 Reply Last reply
        5
        • sierdzioS sierdzio

          moc files are generated by moc tool (Meta Object Compiler) - they are always generated for all QObject classes. They are absolutely required for meta stuff to work, so things like:

          • signals
          • slots
          • Q_INVOKABLE
          • QMeta* classes

          However, these files are generated at build time. You don't need to keep them in your project, same as you don't need to store Makefiles, object files etc.
          Actually, I strongly recommend building your code outside of your source code directory. Qt Creator does this automatically (it's called a "shadow build").

          Other code generators in Qt include:

          • uic (generates UI headers from .ui files)
          • rcc (generates cpp resource files from .qrc files)
          • lupdate/lrelease (for translations)
          P Offline
          P Offline
          Princein
          wrote on last edited by
          #4

          @sierdzio said in when should Generating "moc" files in qt project,and what is the "moc" files's function?:

          moc files are generated by moc tool (Meta Object Compiler) - they are always generated for all QObject classes. They are absolutely required for meta stuff to work, so things like:

          signals
          slots
          Q_INVOKABLE
          QMeta* classes

          However, these files are generated at build time. You don't need to keep them in your project, same as you don't need to store Makefiles, object files etc.
          Actually, I strongly recommend building your code outside of your source code directory. Qt Creator does this automatically (it's called a "shadow build").
          Other code generators in Qt include:

          uic (generates UI headers from .ui files)
          rcc (generates cpp resource files from .qrc files)
          lupdate/lrelease (for translations)

          thank you very much!

          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