Initialize QMap with stream operators?



  • QMap doesn't seem to have a stream operator defined for easy initialization, like so:

    @
    template <class Key, class T>
    QMap<Key, T>& operator<<(QMap<Key, T>& map,
    const QPair<Key, T>& data)
    {
    map.insert(data.first, data.second);
    return map;
    }

    // Use:
    static const QMap<int, QString> someMap =
    QMap<int, QString>() << qMakePair(1, QString("One"))
    << qMakePair(2, QString("Two"));
    @

    Is there a good reason no such operator is defined in Qt?


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.