2

我有一个需要同时使用Qt 3DQCustomPlot库的应用程序。但是,当尝试在其 .pro 文件中使用“QT += 3dinput”的项目中编译 QCustomPlot 时,会出现几个引用QMouseEventQWheelEvent类的错误。

我认为这与Qt3DInput在 QtGui 模块中引入与QMouseEvent和QWheelEvent同名的类这一事实有关,但对 Qt 的内部工作原理不够熟悉,无法理解编译器错误试图告诉我什么。

究竟是什么导致了这个问题,我该如何解决?对 .pro 文件或 QCustomPlot 库本身的修改都是可以接受的。

为了演示该问题,使用以下 .pro 文件编译 QCustomPlot:

QT += widgets printsupport 3dinput
TEMPLATE = lib
SOURCES += qcustomplot.cpp
HEADERS += qcustomplot.h

导致这些错误:

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(); }
                                                                                                    ^

这显然是在使用 MinGW,但 VC++ 会产生类似的错误。

4

0 回答 0