I have an application that requires use of both Qt 3D and the QCustomPlot library. However, when attempting to compile QCustomPlot in a project using "QT += 3dinput" in its .pro file, several errors appear referencing the QMouseEvent and QWheelEvent classes.
I believe this is related to the fact that Qt3DInput introduces classes with the same names as QMouseEvent and QWheelEvent in the QtGui module, but am not familiar enough with the inner workings of Qt to understand what the compiler errors are trying to tell me.
What exactly is causing this issue, and how can I work around it? Modifications to the .pro file or the QCustomPlot library itself are both acceptable.
To demonstrate the problem, compiling QCustomPlot with the following .pro file:
QT += widgets printsupport 3dinput
TEMPLATE = lib
SOURCES += qcustomplot.cpp
HEADERS += qcustomplot.h
Results in these errors:
In file included from C:/Qt/5.7/mingw53_32/include/QtCore/qnamespace.h:43:0,
from C:/Qt/5.7/mingw53_32/include/QtCore/qobjectdefs.h:48,
from C:/Qt/5.7/mingw53_32/include/QtCore/qobject.h:46,
from C:/Qt/5.7/mingw53_32/include/QtCore/QObject:1,
from debug\../../QCustomPlot/qcustomplot.h:29,
from debug\moc_qcustomplot.cpp:9:
C:/Qt/5.7/mingw53_32/include/QtCore/qmetatype.h: In instantiation of 'constexpr int qMetaTypeId() [with T = QMouseEvent*]':
C:/Qt/5.7/mingw53_32/include/QtCore/qmetatype.h:1752:26: required from 'constexpr int qRegisterMetaType() [with T = QMouseEvent*]'
debug\moc_qcustomplot.cpp:2512:84: required from here
C:/Qt/5.7/mingw53_32/include/QtCore/qglobal.h:746:47: error: static assertion failed: Type is not registered, please use the Q_DECLARE_METATYPE macro to make it known to Qt's meta-object system
#define Q_STATIC_ASSERT_X(Condition, Message) static_assert(bool(Condition), Message)
^
C:/Qt/5.7/mingw53_32/include/QtCore/qmetatype.h:1745:5: note: in expansion of macro 'Q_STATIC_ASSERT_X'
Q_STATIC_ASSERT_X(QMetaTypeId2<T>::Defined, "Type is not registered, please use the Q_DECLARE_METATYPE macro to make it known to Qt's meta-object system");
^
In file included from C:/Qt/5.7/mingw53_32/include/QtCore/qobject.h:54:0,
from C:/Qt/5.7/mingw53_32/include/QtCore/QObject:1,
from debug\../../QCustomPlot/qcustomplot.h:29,
from debug\moc_qcustomplot.cpp:9:
C:/Qt/5.7/mingw53_32/include/QtCore/qmetatype.h: In instantiation of 'static constexpr int QMetaTypeId2<T>::qt_metatype_id() [with T = QMouseEvent*]':
C:/Qt/5.7/mingw53_32/include/QtCore/qmetatype.h:1746:43: required from 'constexpr int qMetaTypeId() [with T = QMouseEvent*]'
C:/Qt/5.7/mingw53_32/include/QtCore/qmetatype.h:1752:26: required from 'constexpr int qRegisterMetaType() [with T = QMouseEvent*]'
debug\moc_qcustomplot.cpp:2512:84: required from here
C:/Qt/5.7/mingw53_32/include/QtCore/qmetatype.h:1604:96: error: 'qt_metatype_id' is not a member of 'QMetaTypeId<QMouseEvent*>'
static inline Q_DECL_CONSTEXPR int qt_metatype_id() { return QMetaTypeId<T>::qt_metatype_id(); }
^
C:/Qt/5.7/mingw53_32/include/QtCore/qmetatype.h:1604:100: error: body of constexpr function 'static constexpr int QMetaTypeId2<T>::qt_metatype_id() [with T = QMouseEvent*]' not a return-statement
static inline Q_DECL_CONSTEXPR int qt_metatype_id() { return QMetaTypeId<T>::qt_metatype_id(); }
^
In file included from C:/Qt/5.7/mingw53_32/include/QtCore/qnamespace.h:43:0,
from C:/Qt/5.7/mingw53_32/include/QtCore/qobjectdefs.h:48,
from C:/Qt/5.7/mingw53_32/include/QtCore/qobject.h:46,
from C:/Qt/5.7/mingw53_32/include/QtCore/QObject:1,
from debug\../../QCustomPlot/qcustomplot.h:29,
from debug\moc_qcustomplot.cpp:9:
C:/Qt/5.7/mingw53_32/include/QtCore/qmetatype.h: In instantiation of 'constexpr int qMetaTypeId() [with T = QWheelEvent*]':
C:/Qt/5.7/mingw53_32/include/QtCore/qmetatype.h:1752:26: required from 'constexpr int qRegisterMetaType() [with T = QWheelEvent*]'
debug\moc_qcustomplot.cpp:2540:84: required from here
C:/Qt/5.7/mingw53_32/include/QtCore/qglobal.h:746:47: error: static assertion failed: Type is not registered, please use the Q_DECLARE_METATYPE macro to make it known to Qt's meta-object system
#define Q_STATIC_ASSERT_X(Condition, Message) static_assert(bool(Condition), Message)
^
C:/Qt/5.7/mingw53_32/include/QtCore/qmetatype.h:1745:5: note: in expansion of macro 'Q_STATIC_ASSERT_X'
Q_STATIC_ASSERT_X(QMetaTypeId2<T>::Defined, "Type is not registered, please use the Q_DECLARE_METATYPE macro to make it known to Qt's meta-object system");
^
In file included from C:/Qt/5.7/mingw53_32/include/QtCore/qobject.h:54:0,
from C:/Qt/5.7/mingw53_32/include/QtCore/QObject:1,
from debug\../../QCustomPlot/qcustomplot.h:29,
from debug\moc_qcustomplot.cpp:9:
C:/Qt/5.7/mingw53_32/include/QtCore/qmetatype.h: In instantiation of 'static constexpr int QMetaTypeId2<T>::qt_metatype_id() [with T = QWheelEvent*]':
C:/Qt/5.7/mingw53_32/include/QtCore/qmetatype.h:1746:43: required from 'constexpr int qMetaTypeId() [with T = QWheelEvent*]'
C:/Qt/5.7/mingw53_32/include/QtCore/qmetatype.h:1752:26: required from 'constexpr int qRegisterMetaType() [with T = QWheelEvent*]'
debug\moc_qcustomplot.cpp:2540:84: required from here
C:/Qt/5.7/mingw53_32/include/QtCore/qmetatype.h:1604:96: error: 'qt_metatype_id' is not a member of 'QMetaTypeId<QWheelEvent*>'
static inline Q_DECL_CONSTEXPR int qt_metatype_id() { return QMetaTypeId<T>::qt_metatype_id(); }
^
C:/Qt/5.7/mingw53_32/include/QtCore/qmetatype.h:1604:100: error: body of constexpr function 'static constexpr int QMetaTypeId2<T>::qt_metatype_id() [with T = QWheelEvent*]' not a return-statement
static inline Q_DECL_CONSTEXPR int qt_metatype_id() { return QMetaTypeId<T>::qt_metatype_id(); }
^
This was obviously using MinGW, but VC++ produces similar errors.