Unsolved Qmake did not run moc to generate moc files?
-
I have a class with Q_OBJECT at the top, like you see below. I was under the impression that when I run qmake,
it will generate the moc files that are needed to connect signals and slots. Is that not true?
Currently it is not doing that, and I am getting "missing vtable" errors during the link phase.class MyWindowClass : public QMainWindow { Q_OBJECT //... }
-
@Publicnamer please provide a minimal and reproducible example. Is myWindowClass class in the main.cpp or in a file like mywindowclass.h?
-
@eyllanesc
Why would that main.cpp matter? -
@Publicnamer If the Q_OBJECT macro is not in main.cpp but in foo.h then MOC creates a file foo_moc.h and linked, but if it is in main.cpp then you must include "main.moc" since it is not linked by qmake. If it is the latter then add
#include "main.moc"
beforeint main(...){}
-
@eyllanesc I just put #include "main.moc" in main.cpp but it's unclear where to put Q_OBJECT, because everywhere that I try gives an error.
In file included from /usr/include/aarch64-linux-gnu/qt5/QtCore/qobject.h:46, from /usr/include/aarch64-linux-gnu/qt5/QtCore/qcoreapplication.h:46, from /usr/include/aarch64-linux-gnu/qt5/QtWidgets/qapplication.h:44, from /usr/include/aarch64-linux-gnu/qt5/QtWidgets/QApplication:1, from main.cpp:9: main.cpp:12:1: error: expected unqualified-id before ‘public’ Q_OBJECT ^~~~~~~~ In file included from /usr/include/aarch64-linux-gnu/qt5/QtCore/qglobal.h:105, from /usr/include/aarch64-linux-gnu/qt5/QtGui/qtguiglobal.h:43, from /usr/include/aarch64-linux-gnu/qt5/QtWidgets/qtwidgetsglobal.h:43, from /usr/include/aarch64-linux-gnu/qt5/QtWidgets/qapplication.h:43, from /usr/include/aarch64-linux-gnu/qt5/QtWidgets/QApplication:1, from main.cpp:9: main.cpp:12:1: error: expected declaration before end of line Q_OBJECT ^~~~~~~~
-
@Publicnamer AGAIN: please provide a minimal and reproducible example
-
@eyllanesc
One line fixed it. This really should not be so hard to figure out. Maybe better error messages from qmake would help.HEADERS += MyWindow.h
-
Well MOC runs on the .h files included in the project so if you didn't
include the header file in the .pro file, then MOC would have no
idea it has to process it.