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. Why is qhash not in insertion order?
Forum Update on Monday, May 27th 2025

Why is qhash not in insertion order?

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 3 Posters 654 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.
  • C Offline
    C Offline
    canid
    wrote on last edited by
    #1

    hello,Why is qhash not in insertion order?

    JonBJ 1 Reply Last reply
    1
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi
      Its pr design. For speed. ( insert can be faster )
      If you need it ordered, use QMap.

      C 1 Reply Last reply
      2
      • C canid

        hello,Why is qhash not in insertion order?

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by JonB
        #3

        @canid
        Why should it be? Normal hashing algorithms won't help you at all with insertion order (the order you insert keys into it).

        (BTW, you're not talking about hash key clashes are you?? Or multi-values with same key?)

        @mrjj
        I don't see that QMap would have anything to do with insertion order. (Unless you mean if the input data is ordered in the first place, but the question doesn't imply that.)

        1 Reply Last reply
        4
        • mrjjM mrjj

          Hi
          Its pr design. For speed. ( insert can be faster )
          If you need it ordered, use QMap.

          C Offline
          C Offline
          canid
          wrote on last edited by
          #4

          @mrjj
          hello,It seems that qmap can only be sorted by keys, not by insertion order

          JonBJ mrjjM 2 Replies Last reply
          0
          • C canid

            @mrjj
            hello,It seems that qmap can only be sorted by keys, not by insertion order

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by
            #5

            @canid
            What is it you actually want? A hash table, so that you can very quickly look up by key? But you also want it to be ordered as per the insertions you made??

            1 Reply Last reply
            2
            • C canid

              @mrjj
              hello,It seems that qmap can only be sorted by keys, not by insertion order

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by mrjj
              #6

              @canid
              ah. yes sorry. my bad.
              Read too hasty.
              Map type containers rarely keep insertion order unless made to do so.
              https://github.com/Tessil/ordered-map

              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