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. QJsonArray: Reordering the items
Forum Updated to NodeBB v4.3 + New Features

QJsonArray: Reordering the items

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

    Hi, my QJsonArray example have only 3 QJsonObject items:

    [
        {
            "id": 0,
            "name": "Nyck"
        },
        {
            "id": 1,
            "name": "Paul"
        },
        {
            "id": 2,
            "name": "Raul"
        }
    ]
    

    How can I reorder these QJsonObjects passing the current element index and the future element index?
    I would like to obtain something like this:

    my_array->magic_reorder(2, 0) // This is a "fake" example
    

    The result should be:

    [
        {
            "id": 2,
            "name": "Raul"
        },
        {
            "id": 0,
            "name": "Nyck"
        },
        {
            "id": 1,
            "name": "Paul"
        }
    ]
    

    How can I do this?

    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Since it's a QJsonArray you should take a look at it's functions - esp. at(), operator[] and maybe removeAt()

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      F 1 Reply Last reply
      3
      • Christian EhrlicherC Christian Ehrlicher

        Since it's a QJsonArray you should take a look at it's functions - esp. at(), operator[] and maybe removeAt()

        F Offline
        F Offline
        fem_dev
        wrote on last edited by
        #3

        @christian-ehrlicher thank you!

        I got it working now using:

         my_array->replace(target_id, current_json);
        
        1 Reply Last reply
        0
        • F Offline
          F Offline
          fem_dev
          wrote on last edited by
          #4

          I solved this problem and post a generic solution here:
          https://forum.qt.io/topic/106344/qlistwidget-dragdrop-event-signal/5

          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