Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. How to modify data and save to json file?
Forum Updated to NodeBB v4.3 + New Features

How to modify data and save to json file?

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
16 Posts 9 Posters 11.4k Views 2 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.
  • J josht000

    @sharath Really awesome code snippet! Saved me lots of time, was exactly what I was looking for, and it worked great. Thanks!!!!

    Pablo J. RoginaP Offline
    Pablo J. RoginaP Offline
    Pablo J. Rogina
    wrote on last edited by
    #5

    @josht000 please don't forget to mark your post as solved!

    Upvote the answer(s) that helped you solve the issue
    Use "Topic Tools" button to mark your post as Solved
    Add screenshots via postimage.org
    Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

    SGaistS 1 Reply Last reply
    0
    • Pablo J. RoginaP Pablo J. Rogina

      @josht000 please don't forget to mark your post as solved!

      SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #6

      @Pablo-J-Rogina it's not the original author of this thread ;-)

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      3
      • Y Offline
        Y Offline
        yashnikam
        wrote on last edited by
        #7

        How to add phone numbers in this code snippet?

        jsulmJ 1 Reply Last reply
        0
        • Y yashnikam

          How to add phone numbers in this code snippet?

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

          @yashnikam In the same way it is done for address...

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

          1 Reply Last reply
          1
          • T Offline
            T Offline
            the woft
            wrote on last edited by
            #9

            @SGaist I want to change the value of FirstName and Age , it has no object to find , pls help me !

            JonBJ 1 Reply Last reply
            0
            • T the woft

              @SGaist I want to change the value of FirstName and Age , it has no object to find , pls help me !

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

              @the-woft
              FirstName and Age are in the RootObject just like Address is. Their values will be a string and an integer respectively, so retrievable via QString QJsonValue::toString() const & int QJsonValue::toInt(int defaultValue = 0) const and modifiable via QJsonValueRef QJsonObject::operator[](const QString &key).

              T 1 Reply Last reply
              0
              • JonBJ JonB

                @the-woft
                FirstName and Age are in the RootObject just like Address is. Their values will be a string and an integer respectively, so retrievable via QString QJsonValue::toString() const & int QJsonValue::toInt(int defaultValue = 0) const and modifiable via QJsonValueRef QJsonObject::operator[](const QString &key).

                T Offline
                T Offline
                the woft
                wrote on last edited by
                #11

                @JonB said in How to modify data and save to json file?:

                FirstName and Age are in the RootObject just like Address is. Their values will be strings, so retrievable via QString QJsonValue::toString() const and modifiable via QJsonValueRef QJsonObject::operator[](const QString &key).

                i'm newbie in qt and i try it but not correct , you can give me sample code do it ?

                jsulmJ 1 Reply Last reply
                0
                • T the woft

                  @JonB said in How to modify data and save to json file?:

                  FirstName and Age are in the RootObject just like Address is. Their values will be strings, so retrievable via QString QJsonValue::toString() const and modifiable via QJsonValueRef QJsonObject::operator[](const QString &key).

                  i'm newbie in qt and i try it but not correct , you can give me sample code do it ?

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

                  @the-woft said in How to modify data and save to json file?:

                  and i try it but not correct

                  Then show what you tried.
                  There is example code in documentation and example applications like https://doc.qt.io/qt-6/qtcore-serialization-savegame-example.html

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

                  T 1 Reply Last reply
                  0
                  • jsulmJ jsulm

                    @the-woft said in How to modify data and save to json file?:

                    and i try it but not correct

                    Then show what you tried.
                    There is example code in documentation and example applications like https://doc.qt.io/qt-6/qtcore-serialization-savegame-example.html

                    T Offline
                    T Offline
                    the woft
                    wrote on last edited by
                    #13

                    @jsulm this my code
                    QJsonValue Age = root_object.value("Age");
                    QVariant tmp = Age.toVariant();
                    qlonglong result = root_object.value("Age").toVariant().toLongLong();
                    QJsonValueRef ref = RootObject("result");
                    QJsonObject m_addvalue = ref.toObject();

                    JonBJ 1 Reply Last reply
                    0
                    • T the woft

                      @jsulm this my code
                      QJsonValue Age = root_object.value("Age");
                      QVariant tmp = Age.toVariant();
                      qlonglong result = root_object.value("Age").toVariant().toLongLong();
                      QJsonValueRef ref = RootObject("result");
                      QJsonObject m_addvalue = ref.toObject();

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

                      @the-woft
                      You read the Age entry in root_object but where do you set the Age entry in root_object? You don't. I gave you the reference to QJsonValueRef QJsonObject::operator[](const QString &key) to use.

                      T 1 Reply Last reply
                      0
                      • JonBJ JonB

                        @the-woft
                        You read the Age entry in root_object but where do you set the Age entry in root_object? You don't. I gave you the reference to QJsonValueRef QJsonObject::operator[](const QString &key) to use.

                        T Offline
                        T Offline
                        the woft
                        wrote on last edited by
                        #15

                        @JonB was exactly what I was looking for, and it worked great. Thanks!!!!

                        JonBJ 1 Reply Last reply
                        0
                        • T the woft

                          @JonB was exactly what I was looking for, and it worked great. Thanks!!!!

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

                          @the-woft For other readers you might post the line of code you added to set rootObject["Age"] correctly.

                          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