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
54
votes
4 answers

Qt compiler warning: overriding commands for target / ignoring old commands for target

When I'm compiling my Qt project for Windows I receive these 2 warnings: Makefile.Debug:109: warning: overriding commands for target `debug/moc_mainwindow.cpp' Makefile.Debug:106: warning: ignoring old commands for target…
sashoalm
  • 75,001
  • 122
  • 434
  • 781
20
votes
4 answers

Qt moc with implementations inside of header files?

Is it possible to tell the Qt MOC that I would like to declare the class and implement it in a single file rather than splitting them up into an .h and .cpp file?
user336063
18
votes
2 answers

Why is important to include ".moc" file at end of a Qt Source code file?

Why is it important to add an include for .moc file in a Qt cpp source code? This is a common step used in several Qt samples, including this one: http://doc.qt.io/qt-5/qttestlib-tutorial1-example.html; where the line #include "testqstring.moc"…
Daniel Santos
  • 14,328
  • 21
  • 91
  • 174
18
votes
3 answers

Qt 5 cmake fails with undefined reference to vtable on hello world with inc & src as subdirs

Update 2 After messing around a bit (and some editing of the generated Makefiles), it looks like what is happening is that moc is not properly processing MainWindow.h (included by main.cpp and MainWindow.cpp unless it is in the same folder as the…
Iskar Jarak
  • 5,136
  • 4
  • 38
  • 60
16
votes
1 answer

Use C++-slot in QML which returns type in namespace

I first want to mention that the following worked fine up to Qt 5.0.0 beta 1 (maybe beta 2 and RC too, don't know), but fails in Qt 5.0.0 final release version. I only want to refer to the results seen in Qt 5.0.0 final release version. So most…
leemes
  • 44,967
  • 21
  • 135
  • 183
14
votes
2 answers

Use Boost.Signal instead of Qt's signals? Do without moc?

I know they can be used together, but I'm wondering whether it's possible to replace Qt's signals and slots mechanism with Boost.Signal in the Qt parts of the program (widgets and such). Anyone ever try it? Any gotchas? Assuming I don't use any…
drby
  • 2,619
  • 25
  • 26
12
votes
2 answers

How do you get cmake to add compiler definitions only for automoc files

Our project is using very strict set of warnings, but Qt5 generated moc files produce code that violates these warnings. We could obviously turn off the warnings globally, but I'd like to just suppress the warnings for the automoc files. For…
Steve Broberg
  • 4,255
  • 3
  • 28
  • 40
11
votes
1 answer

Multiple definitions error: one in my file and one in the moc file.

I have a class called FindAndReplaceBar, whose implementation is this: #include "FindAndReplaceBar.h" #include #include #include #include #include…
W.K.S
  • 9,787
  • 15
  • 75
  • 122
11
votes
2 answers

Qt/Qml and method overloads

Just came across a weird behavior of Qt framework while invoking overloaded C++ methods from within Qml and trying to understand the reason behind it. Let's say I have a QList-like class with the following methods: ... Q_SLOT void…
gplusplus
  • 336
  • 1
  • 5
  • 12
11
votes
2 answers

How to instruct cmake/automoc to find external header

I have a Qt widget C++ class that loads a ui file created in Qt Creator. The header and the source file for the class live in two separate directories. I have trouble instructing cmake/automoc to find the header for the class. cmake recognizes it…
user2180977
  • 401
  • 3
  • 14
10
votes
1 answer

Qt "signal undefined reference error" after inheriting from QObject

I recently needed to add a signal to a class, so I changed the class to inherit from QObject and added the Q_OBJECT macro into the class definition. Since doing so I get "signal undefined reference error for 'vtable for CLICommand'" error on the…
TSG
  • 4,242
  • 9
  • 61
  • 121
9
votes
7 answers

How to add specific flags to moc in a qmake project?

I compile a Qt executable using qmake && make on the following project.pro file: INCLUDEPATH *= ../../dependencies/boost QT *= opengl xml CONFIG *= qt opengl static TARGET = myexe HEADERS = Viewer.hpp MainWindow.hpp Inspector.hpp SOURCES = main.cpp…
F'x
  • 12,105
  • 7
  • 71
  • 123
9
votes
2 answers

How to create dynamic signals and slots in Qt?

The signal/slot mechanism in Qt, is a static mechanism. The classes have to be preprocessed by the moc compiler. Now I want to create signals and slots dynamically at run-time. I already have a working solution, but it feels to me like a hack,…
Kurt Pattyn
  • 2,758
  • 2
  • 30
  • 42
8
votes
1 answer

Difference between Kahn Process Network and Actor Model

I was wondering what is the actual difference between Kahn Process Network and Actor Model. Indeed, if I look up at the definition, they both are models in which computational entities (called Actors in both cases...) exchange messages via unbounded…
user829249
8
votes
4 answers

Why does this Simple Qt Application not link

I tried to write a simple Qt application like this: main.cpp: #include class MyApp : public QApplication { Q_OBJECT public: MyApp(int argc, char* argv[]); }; MyApp::MyApp(int argc, char* argv[]) : …
Karsten
  • 1,814
  • 2
  • 17
  • 32
1
2 3
14 15