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. QHash remove item while iterating?
Qt 6.11 is out! See what's new in the release blog

QHash remove item while iterating?

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 2 Posters 521 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.
  • P Offline
    P Offline
    Publicnamer
    wrote on last edited by
    #1

    I'm interating through a QHash and I want to modify the key of an item as I find it.
    e.g.

    if (i.key() == 123) then { 
       // remove this item to reinsert later with a key of 456
    }
    

    However can I remove the item during the iteration?
    Or better yet, is there a way to modify the key on the fly without doing a remove+insert?

    jsulmJ 1 Reply Last reply
    0
    • P Publicnamer

      I'm interating through a QHash and I want to modify the key of an item as I find it.
      e.g.

      if (i.key() == 123) then { 
         // remove this item to reinsert later with a key of 456
      }
      

      However can I remove the item during the iteration?
      Or better yet, is there a way to modify the key on the fly without doing a remove+insert?

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Publicnamer It's all in the documentation: https://doc.qt.io/qt-5/qhash.html#erase

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1

      • Login

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