Can i use QHash.toMap?



  • Hello!
    can i converte QHash to QMap?



  • Not directly, but the code to make the conversion is trivial I'd say.

    Something like this should do the trick:
    @
    //sample only, code completely untested.
    template <typename Key, typename Value>
    QMap<Key, Value> hashToMap(const QHash<Key, Value> hash) {
    QMap<key, Value> result;
    QHashIterator<Key, Value> it(hash);
    while (it.hasNext()) {
    it.next();
    result.insert(it.key(), it.value());
    }
    return result;
    }
    @


Log in to reply
 

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