How to insert hash value from a QStringList using a for loop (solved)



  • error:
    error: no match for 'operator[]' in StationHash.QHash <k,v)::value
    @
    QStringList StationList
    QHash<int, QString> stationHash;

    QHash<int, QString> ::iterator i;
    for(i=StationHash.begin(); i !=StationHash.end(); ++i)
    {
    StationHash.value[i]= StationList[i];
    }

    @



  • If you are inserting from StationList to stationHash then stationHash is empty and your loop will never be executes.

    i is an iterator. You can not use iterator as an index.

    Why do you need a string hash that replicates a string list

    Anyway, try this
    @
    for (int i = 0; i < StationList.size(); ++i) {
    stationHash.insert(i, StationList[i])
    }
    @


Log in to reply
 

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