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
2
votes
1 answer

Why does AUTOMOC fail, if both find_package() and qt5_use_modules() are called from functions?

I am trying to compile some Qt project, including the QCustomPlot library. As a minimum example, i set up a project consisting of: qcustomplot.h qcustomplot.cpp CMakeLists.txt ../cmake/QCustomPlot.cmake The original project is bigger, but the…
Anedar
  • 4,235
  • 1
  • 23
  • 41
2
votes
1 answer

How to use moc in a qmake project that doesn't use Qt modules?

I have a qmake project that includes the needed Qt source files directly, thus I don't need to link with any Qt libraries: TEMPLATE = app CONFIG -= qt Yet the removal of Qt support also forces qmake not to process any headers with moc. Is there a…
Kuba hasn't forgotten Monica
  • 95,931
  • 16
  • 151
  • 313
2
votes
2 answers

c++ macro containing Q_OBJECT

I'm developping a c++/Qt program that will have several plugins. For each class I have to define a plugin-interface that looks like this: //my class class qwerty; //my interface class qwertyPlug : public QObject, myPlug { Q_OBJECT…
bibi
  • 3,671
  • 5
  • 34
  • 50
2
votes
1 answer

CMake with Qt: moc creates .cpp_parameters ending

I am trying to integrate Qt in my project, especially QTimer. Therefore, I have been trying to generate the moc files with cmake: set(MOC_FILES ${CMAKE_CURRENT_SOURCE_DIR}/../headerfile.h ) set(HEADER_FILES ... …
user4911648
2
votes
0 answers

QT Visual Studio plugin fails automatic moc with non-standard header extensions

I am currently trying to port a very large project to QT. Many of the headers in this project use the file extension .hh . I would ideally like to avoid having to rename all of these files, but it appears to be causing some issues for the QT Visual…
Owen
  • 209
  • 1
  • 13
2
votes
1 answer

#if defined WINDOWS vs #if defined(WINDOWS)

Does enclosing the definition in parenthesis make any difference? I'm asking because the Qt moc compiler crashes when it sees the latter variant enclosed in parenthesis and WINDOWS is defined. Update: Upgraded from Qt 5.4.2 to Qt 5.6 and I no longer…
Petter Kvalvaag
  • 323
  • 2
  • 11
2
votes
1 answer

How to define signals with macros in Qt

I try to create a some standart signal definitionsfor some classes with macros like: #define CREATE_SIGNALS signals: void error_signal(QString error); Functions are created, but moc did not create methods for these functions. It seems that moc is…
fyo
  • 77
  • 2
  • 13
2
votes
1 answer

Qt plugins: is there a way to list all interfaces a plugin implements?

I have a Qt application that allows custom plugins (loaded with QPluginLoader), and these plugins can implement some interfaces, and declare with the Q_INTERFACES() macro. If you look at Qt's documentation linked below, I'm talking about the…
Daniele
  • 410
  • 7
  • 19
2
votes
1 answer

How to determine if give a property isn't inherited from base class?

How to determine if give a property isn't inherited from base class? I'm converting an object to a QVariantList and I'd like to keep out of my list the inherited properties from base class, like objectName from QObject QVariantList list; const…
Jack
  • 16,276
  • 55
  • 159
  • 284
2
votes
1 answer

How to view the exact command cmake_automoc is running?

I have an issue with automoc in that moc fails with Parse error at "BOOST_JOIN". I tried the "least evil" hack outlined here, but to no avail (speficially, I added set(CMAKE_AUTOMOC_MOC_OPTIONS "-DBOOST_TT_HAS_OPERATOR_HPP_INCLUDED") to my…
Claudiu
  • 224,032
  • 165
  • 485
  • 680
2
votes
2 answers

MOC adding namespace to class names

I have this very strange problem while compiling the project. MOC seems to be adding a namespace to the class name being moc'ed, although it's not mentioned anywhere in the file/class. The namespace, however, exists in a library which I use, but…
Florin
  • 2,891
  • 4
  • 19
  • 26
2
votes
2 answers

MOC a lambda connection

I'd like to create a connection like so: connect(myMap[myObjectName], &myObject::valueChanged, [&] (int value) { QString objectName = sender()->objectName(); myOtherMap[objectName].setValue(QVariant(value)); }); This doesn't work though…
Nicolas Holthaus
  • 7,763
  • 4
  • 42
  • 97
2
votes
2 answers

Style sheet is appliped to the cells in QGridLayout instead of the parent container

I have inherited QWidget to make a class called (lets say..) TaskBox. I've applied a QGridLayout to my TaskBox. The layout consists of several QLabels. I've changed the background color of the TaskBox by setting a style sheet for it. Now it looks…
Naveen
  • 623
  • 9
  • 20
2
votes
1 answer

Closest solution to multiple inheritance through QObject subclasses

I have multiple QObject subclasses which should act as interface classes and be implemented by (inherited by) some other classes. For example let class A : virtual public QObject and class B : virtual public QObject be interface classes. I need a…
sorush-r
  • 10,490
  • 17
  • 89
  • 173
2
votes
1 answer

Qt SLOT macro used as function argument

I'm going through the calculator example that was installed with Qt 5.1.1 and there is a private function used to create button widgets (Button inherits QToolButton): Button *Calculator::createButton(const QString &text, const char *member) { …
DanielJG
  • 365
  • 1
  • 3
  • 13