Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Solved Why can't qjsonvalue directly convert data to int but indirectly through toVariant?

    General and Desktop
    3
    8
    322
    Loading More Posts
    • 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
      canid last edited by

      Why can't qjsonvalue directly convert data to int but indirectly through toVariant?

      jsulm 1 Reply Last reply Reply Quote 0
      • jsulm
        jsulm Lifetime Qt Champion @canid last edited by

        @canid
        ?
        What about https://doc.qt.io/qt-5/qjsonvalue.html#toInt ?

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

        C 1 Reply Last reply Reply Quote 1
        • C
          canid @jsulm last edited by

          @jsulm
          This class does have the function toInt, but I found that the conversion with this function is 0, which requires toVariant to convert correctly

          jsulm 1 Reply Last reply Reply Quote 0
          • jsulm
            jsulm Lifetime Qt Champion @canid last edited by

            @canid Can you show your JSON? toInt() returns 0 if it can't convert the value to an integer.

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

            C 1 Reply Last reply Reply Quote 3
            • C
              canid @jsulm last edited by

              @jsulm
              {"user":{"id":"1","username":"admin1","realname":"canid","type":"1"}}
              The data for this "type" cannot be converted to int

              Pl45m4 jsulm 2 Replies Last reply Reply Quote 0
              • Pl45m4
                Pl45m4 @canid last edited by

                @canid

                Show your JSON Parse. You sure, that you really access the value of key "type" and nothing else?


                If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                ~E. W. Dijkstra

                1 Reply Last reply Reply Quote 0
                • jsulm
                  jsulm Lifetime Qt Champion @canid last edited by

                  @canid You're storing numbers as strings, why? That's why toInt() doesn't work.

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

                  C 1 Reply Last reply Reply Quote 5
                  • C
                    canid @jsulm last edited by

                    @jsulm
                    Ok, got it. Thank you

                    1 Reply Last reply Reply Quote 0
                    • First post
                      Last post