Search code examples
qtqmap

nested QMap in qt


I am trying to use this code in my QT app

QMap<QString,QMap>

but there is a build problem it says

C:/****/****/****/***/domparser.h:14: error: type/value mismatch at argument 2 in template parameter list for 'template<class Key, class T> class QMap'

Solution

  • QMap is a template class, so you need to specify the type of the inner QMap like this :

    QMap<String, QMap<QString, int> > myMap;
    

    Note the space between the '>'s otherwise the C++ lexer thinks its the >> operator.

    [edited]

    If you intended to try to store a generic QMap as the value type, rather than a concrete instance of QMap, within your outer map, you can't!

    You cannot have something like QMap, because QMap itself is not a type, its a template - it only names a type when the template parameters are specified