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

Fresh binary install of QT5.2.1 for MSVC2010 - qmap.h error



  • My app builds fine with QT5.1.1 using msvc2010 (32bit). Installed the binary build of QT5.2.1 for MSVC10 32bit.

    Get this error:

    C:\Qt\5.2.1\msvc2010\include\QtCore/qmap.h(216) : error C2059: syntax error : '&'
    C:\Qt\5.2.1\msvc2010\include\QtCore/qmap.h(212) : while compiling class template member function 'QMapNode<Key,T> *QMapData<Key,T>::createNode(const Key &,const T &,QMapNode<Key,T> *,bool)'
    with
    [
    Key=QString,
    T=QVariant
    ]
    C:\Qt\5.2.1\msvc2010\include\QtCore/qmap.h(333) : see reference to class template instantiation 'QMapData<Key,T>' being compiled
    with
    [
    Key=QString,
    T=QVariant
    ]
    C:\Qt\5.2.1\msvc2010\include\QtCore/qmap.h(333) : while compiling class template member function 'QMap<Key,T>::QMap(void)'
    with
    [
    Key=QString,
    T=QVariant
    ]
    C:\Qt\5.2.1\msvc2010\include\QtCore/qvariant.h(501) : see reference to class template instantiation 'QMap<Key,T>' being compiled
    with
    [
    Key=QString,
    T=QVariant
    ]
    C:\Qt\5.2.1\msvc2010\include\QtCore/qmap.h(216) : error C2143: syntax error : missing ';' before ')'
    C:\Qt\5.2.1\msvc2010\include\QtCore/qmap.h(216) : error C2143: syntax error : missing ';' before ')'
    C:\Qt\5.2.1\msvc2010\include\QtCore/qmap.h(218) : error C2059: syntax error : '&'
    C:\Qt\5.2.1\msvc2010\include\QtCore/qmap.h(218) : error C2143: syntax error : missing ';' before ')'
    C:\Qt\5.2.1\msvc2010\include\QtCore/qmap.h(218) : error C2143: syntax error : missing ';' before ')'



  • It took me some hairs of my head, but I found the problem.
    Some library headers in debug mode redefine the 'new' operator in order to catch memory leaks; something like this:

    @#define new new( _NORMAL_BLOCK, FILE, LINE)@

    The problem is with this lines in qmap.h, where they use the new operator in a very unusual way.

    @
    QT_TRY{
    new (&n->key) Key(k); /* !!! /
    QT_TRY{
    new (&n->value) T(v); /
    !!! */
    @

    The workaround is to undef the new operator before the qt headers.
    @
    #undef new
    #include "qt_header.h"
    @

    I don't know if it can be considered a bug, but certainly it is source of troubles.


  • Lifetime Qt Champion

    Hi,

    No it's not, generally on Windows you would include Windows specific headers after Qt's


Log in to reply