Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to insert hash value from a QStringList using a for loop (solved)
Forum Update on Monday, May 27th 2025

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

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 966 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    houmingc
    wrote on 16 Dec 2014, 02:29 last edited by
    #1

    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];
    }

    @

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andreyc
      wrote on 16 Dec 2014, 06:03 last edited by
      #2

      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])
      }
      @

      1 Reply Last reply
      0

      1/2

      16 Dec 2014, 02:29

      • Login

      • Login or register to search.
      1 out of 2
      • First post
        1/2
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved