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. QJsonDocument auto sorting
Qt 6.11 is out! See what's new in the release blog

QJsonDocument auto sorting

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 3.0k Views 1 Watching
  • 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.
  • N Offline
    N Offline
    ningu
    wrote on last edited by
    #1

    Hi,

    I'm loading some data from a JSON file to a QJsonDocument, editing, and writing back to file. I see that QJsonDocument automatically sorts objects alphabetically. So when I write to file, everything is sorted in that order, which I would like not happen. Is there a way to avoid this?

    Cheers.

    1 Reply Last reply
    1
    • Chris KawaC Online
      Chris KawaC Online
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by
      #2

      AFAIK you can't. A JSON object is an unordered set of name-value pairs. This means that the order is implementation specific. In case of Qt this is probably (I haven't checked) a QMap, which holds its data in sorted-by-key order.

      1 Reply Last reply
      0
      • N Offline
        N Offline
        ningu
        wrote on last edited by
        #3

        Ok. That's more or less what I thought. Thank you very much!

        1 Reply Last reply
        0

        • Login

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