Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

[SOLVED] QT 5.2.0: Q_DECLARE_METATYPE requires value_type and other sequential class attributes to be defined



  • I have a code that compiles and runs fine under QT 5.1.1. After upgrading to QT 5.2.0, I got errors:

    @
    c:\qt\qt5.2.0\5.2.0\msvc2012_64\include\qtcore\qmetatype.h(1372) : error C2039: 'value_type' : is not a member of 'MyTemplateClass<T>'
    with
    [
    T=float
    ]
    c:\qt\qt5.2.0\5.2.0\msvc2012_64\include\qtcore\qmetatype.h(1578) : see reference to class template instantiation 'QtPrivate::SequentialContainerConverterHelper<T>' being compiled
    with
    [
    T=MyTemplateClassFlt
    ]
    c:\qt\qt5.2.0\5.2.0\msvc2012_64\include\qtcore\qmetatype.h(1600) : see reference to function template instantiation 'int qRegisterNormalizedMetaType<T>(const QByteArray &,T *,QtPrivate::MetaTypeDefinedHelper<T,defined>::DefinedType)' being compiled
    with
    [
    T=MyTemplateClassFlt,
    defined=true
    ]
    d:\users\vlad\vsprojects\qt\cmpt\libcc\libcct\MyTemplateClass.h(736) : see reference to function template instantiation 'int qRegisterMetaType<MyTemplateClassFlt>(const char *,T *,QtPrivate::MetaTypeDefinedHelper<T,defined>::DefinedType)' being compiled
    with
    [
    T=MyTemplateClassFlt,
    defined=true
    ]
    c:\qt\qt5.2.0\5.2.0\msvc2012_64\include\qtcore\qmetatype.h(1372) : error C2146: syntax error : missing ',' before identifier 'value_type'
    c:\qt\qt5.2.0\5.2.0\msvc2012_64\include\qtcore\qmetatype.h(1372) : error C2065: 'value_type' : undeclared identifier
    c:\qt\qt5.2.0\5.2.0\msvc2012_64\include\qtcore\qmetatype.h(1382) : error C2955: 'QMetaTypeId2' : use of class template requires template argument list
    c:\qt\qt5.2.0\5.2.0\msvc2012_64\include\qtcore\qmetatype.h(1479) : see declaration of 'QMetaTypeId2'

    @
    These errors are generated from the line:
    @
    typedef MyTemplateClass<float> MyTemplateClassFlt; Q_DECLARE_METATYPE(MyTemplateClassFlt)
    @

    MyTemplateClass is a simple template class which is not based on a sequential container. Why 5.2.0's Q_DECLARE_METATYPE now requires "T::value_type" and other attributes of sequential classes?

    Is this a bug on 5.2.0 or my code is implicitly broken with undetectable under 5.1.1 problems?



  • To leave this thread with an answer, it appeared that I was using Q_DECLARE_METATYPE_TEMPLATE_1ARG macro, which came quite handy to me, but that macro is not documented in QT and they changed its behavior, starting from 5.2.0.


Log in to reply