解决Qt单元测试自定义类型报错的问题

来源:互联网 发布:node 绑定域名 编辑:程序博客网 时间:2024/06/14 06:03
  QTest::addColumn< QList<IndexStForQuery> >("idxinfolist");
  QTest::addColumn< FulldisDataType>("datatype");

  QTest::addColumn< FulldisDataName>("dataname");

编译报错如下:

/opt/linux_virtual/qt/qt-4.8.6/pc/include/QtCore/qmetatype.h:169: error: 'qt_metatype_id' is not a member of 'QMetaTypeId<QList<IndexStForQuery> >'

/opt/linux_virtual/qt/qt-4.8.6/pc/include/QtCore/qmetatype.h:169: error: 'qt_metatype_id' is not a member of 'QMetaTypeId<FulldisDataType>'

/opt/linux_virtual/qt/qt-4.8.6/pc/include/QtCore/qmetatype.h:169: error: 'qt_metatype_id' is not a member of 'QMetaTypeId<FulldisDataName>'


后来查阅资料,

需要将自定义类型声明为QMetaType

在定义这个类的头文件中使用宏 Q_DECLARE_METATYPE()就好,解决方法如下:

Q_DECLARE_METATYPE(FulldisDataType)
Q_DECLARE_METATYPE(QList<IndexStForQuery>)
Q_DECLARE_METATYPE(FulldisDataName)

0 0