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

Multiple qRegisterMetaType<T>() result in Binary compatibility break.



  • Hi everyone,
    I'm getting headaches trying to expose a class to both ActiveX and QtScript.
    In order to expose it to activeX, I use Qt macro QAXCLASS(MyClass) which will call :

    #define QAXCLASS(Class)
    factory = new QAxClass<Class>(typeLibID().toString(), appID().toString());
    qRegisterMetaType<Class*>(#Class"*");
    [snip]

    Later in my dll handling the script, I will register the class qScriptRegisterMetaType<MyClass*>(eng, qObjectToScriptValue, qObjectFromScriptValue) which will call

    template<typename T>
    int qScriptRegisterMetaType(
        QScriptEngine *eng,
        QScriptValue (*toScriptValue)(QScriptEngine *, const T &t),
        void (*fromScriptValue)(const QScriptValue &, T &t),
        const QScriptValue &prototype = QScriptValue()
    #ifndef qdoc
        , T * /* dummy */ = 0
    #endif
    )
    {
        const int id = qRegisterMetaType<T>(); // make sure it's registered
    [snip]
    

    this will compile and link, but on execution I get a qFatal stating that:

    QMetaType::registerType: Binary comaptibility break. Type flags for type 'MyClass*' [2258] don't match. Previously registered TypeFlags(0x104), now registering TypeFlags(0x10c)

    Since all these codes are hidden in Qt macro, is there anything I can do?
    Thanks in advance for your help


  • Lifetime Qt Champion

    Hi
    Its not something with const ?
    https://bugreports.qt.io/browse/QTBUG-47631

    Seems to be the same TypeFlags values in the bug report but
    im not aware if other qRegisterMetaType scenarios result in same
    ID/values for TypeFlags.



  • No I'm not trying to register const.
    However the first registration happen in the main app (QAXCLASS macro) while the latter is called from a plugin.


  • Lifetime Qt Champion

    @JulienMaille
    Hmm, searching Google that error also seen when plugin loaded another version
    of Qt Dlls. ( than main app)
    I assume this cant be the case ?



  • Yes this can't be the case. (the funny part is it compiles fine with Qt4)



  • I finally found the trick. Write my own macro that doesn't blindly call qRegisterMetaType

    #define MYAXTYPE(Class) \
        factory = new MyAxType<Class>(typeLibID().toString(), appID().toString()); \
        if( !QMetaType::isRegistered(QMetaType::type(#Class"*")) ) \
            qRegisterMetaType<Class*>(#Class"*"); \
        keys = factory->featureList(); \
        for (it = keys.begin(); it != keys.end(); ++it) { \
            factoryKeys += *it; \
            factories.insert(*it, factory); \
            creatable.insert(*it, false); \
        }\
    

Log in to reply