I'm using a QMultiMap to parse a file, and when i store all my elements in the QMultiMap i find out that it's sorted alphabetically by the Keys and it wrongs my parsing because i have to keep the natural order of the original file while adding the elements in the QMultiMap

In the MultiMap normal c++ function, i think we can change the sorting method


    class Key,
    class T,
    class Compare = std::less<Key>,
    class Allocator = std::allocator<std::pair<const Key, T> >
> class multimap;

Thanks to the Compare function, but this compare function doesn't exist in the Qt function QMultiMap

The Qt function defined in qmap.h is the following

 inline typename QMap<Key, T>::iterator insert(typename QMap<Key, T>::const_iterator pos, const Key &key, const T &value)
{ return QMap<Key, T>::insertMulti(pos, key, value); }

template <class Key, class T>
Q_INLINE_TEMPLATE typename QMap<Key, T>::iterator QMap<Key, T>::insertMulti(const Key &akey,
                                                                            const T &avalue)
    Node* y = d->end();
    Node* x = static_cast<Node *>(d->root());
    bool left = true;
    while (x != nullptr) {
        left = !qMapLessThanKey(x->key, akey);
        y = x;
        x = left ? x->leftNode() : x->rightNode();
    Node *z = d->createNode(akey, avalue, y, left);
    return iterator(z);

0 Answers