Questions tagged [moc]

MOC is Qt's Meta Object Compiler. It transforms certain Qt-specific macros into the C++ code and meta information necessary for Qt's signal and slots, RTTI, and the dynamic property system.

The meta-object system is based on three things:

  1. The QObject class provides a base class for objects that can take advantage of the meta-object system.
  2. The Q_OBJECT macro inside the private section of the class declaration is used to enable meta-object features, such as dynamic properties, signals, and slots.
  3. The Meta-Object Compiler (moc) supplies each QObject subclass with the necessary code to implement meta-object features.
216 questions
3
votes
0 answers

Qt Creator setting moc parameters

I'm trying to move my project from the VS2005 build system to Qt Creator. We've set up visual studio to use moc for certain headers and output a .moc file with the same file name. eg: MyClass.h MyClass.moc When QtCreator runs qmake and moc is run,…
Boumbles
  • 2,473
  • 3
  • 24
  • 42
3
votes
2 answers

Building a plugin to extend a Qt application

I decided to switch my hobby project application (a dictionary lookup program) to a plugin architecture to enable all kinds of different dictionaries to be developed for other languages in the future. The application is developed in Visual C++ with…
neuviemeporte
  • 6,310
  • 10
  • 49
  • 78
3
votes
1 answer

Errors in generated MOC files for QT5 from cmake

I generated moc files for QT5 using set (CMAKE_AUTOMOC ON) set(CMAKE_INCLUDE_CURRENT_DIR ON) Then I add the moc files into SRC using SET(SRC src/main.cpp src/video_widget_surface.cpp src/video_widget.cpp src/video_player.cpp #moc files …
navderm
  • 799
  • 2
  • 11
  • 33
3
votes
1 answer

CMake: 'AUTOMOC' feature skips sources of executable targets?

There is a medium-sized project with a top level CMakeLists.txt which defines some common stuff and invokes the configuration of all artifacts (subprojects) in the project like…
Alexander Shukaev
  • 16,674
  • 8
  • 70
  • 85
2
votes
1 answer

Qt program does not link, no moc file generated

I'm using Qt, CMake, and the VS2010 compiler. There seems to be a problem when I'm linking a small piece of test code. The linkers gives the following error: plotter.cpp.obj : error LNK2001: unresolved external symbol "public: virtual str uct…
user1254962
  • 153
  • 5
  • 15
2
votes
1 answer

Should I compile Qt VS use the online installer?

I compiled Qt5 by myself years ago for a Linux project. These days I'm working on Windows and I install Qt5 using the online installer. Here and there however I face indications that compiling Qt might led to a better debugging experience, last time…
KcFnMi
  • 5,516
  • 10
  • 62
  • 136
2
votes
1 answer

Should I use #ifndef Q_MOC_RUN as much a possible?

I have a Qt/C++ project that uses Boost library, and I see Boost headers are included like this: #ifndef Q_MOC_RUN #include #include #endif I read that if you…
Glinka
  • 483
  • 1
  • 3
  • 18
2
votes
3 answers

How to add defines to moc_predefs.h?

Qt's moc.exe generates files moc_predefs.h, that contain some defines, that are included to every file that moc parses. Is there a way to add defines to these files? I'd like to define some include guards in these files to prevent moc.exe from…
Jaa-c
  • 5,017
  • 4
  • 34
  • 64
2
votes
1 answer

Why is cmake not mocing my Q_OBJECT headers?

I currently have a project set up like this: - project/ --- include/ --- src/ --- qml/ --- CMakeLists.txt --- qml.qrc And a CMakeLists.txt like this: cmake_minimum_required(VERSION 3.1) cmake_policy(SET CMP0071…
iHowell
  • 2,263
  • 1
  • 25
  • 49
2
votes
1 answer

How can I use cascaded namespaces in moc files?

I'm currently writing a small application with Qt (4.7). And I use nested namespaces like namespace app { namespace core { class CoreClass {...} } } Because I'm a litte bit lazy, I am using symbols for shortcuts that hold the…
Christian Smolka
  • 159
  • 1
  • 10
2
votes
1 answer

CMake Automoc Error 1 - Can't compile project

I just moved a project I built in Qt5 into my CMake project tree. I exported the project in the CMake directory. However as I try to build the project the compiler gives me the following…
user9174145
2
votes
2 answers

Why is it possible to connect to a function that is not declared as Q_SLOTS?

I 'accidentally' connected a signal to QWidget::setToolTip(): bool ok = connect(source, &Source::textSignal, widget, &QWidget::setToolTip); Q_ASSERT(ok); ... and it worked. Not only did the connection succeed, the function was also invoked…
Martin Hennings
  • 16,418
  • 9
  • 48
  • 68
2
votes
1 answer

What are the sections in Qt's MOC generated .cpp file?

Can someone please explain the sections in the file and their significance? How are signals and slots made available for calling?
Sulla
  • 7,631
  • 9
  • 45
  • 71
2
votes
3 answers

CMake AutoMOC generates .cpp with errors

I have a project that is being generated via CMake that also uses the AutoMOC flag. However, when I open the solution and try to build the project (using the Visual Studio 15 2017 x64 generator), this particular project fails. I'll post the error…
andyopayne
  • 1,348
  • 3
  • 24
  • 49
2
votes
2 answers

How to generate moc_*.cpp files using CMake

Suppose I have a C++ file named animals.cpp. How can I generate a moc file (moc_animals.cpp) using CMake?
Amani
  • 16,245
  • 29
  • 103
  • 153