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 can't qjsonvalue directly convert data to int but indirectly through toVariant?

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

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 3 Posters 734 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

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

    jsulmJ 1 Reply Last reply
    0
    • C canid

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

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

      @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
      1
      • jsulmJ jsulm

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

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

        @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

        jsulmJ 1 Reply Last reply
        0
        • C canid

          @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

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

          @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
          3
          • jsulmJ jsulm

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

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

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

            Pl45m4P jsulmJ 2 Replies Last reply
            0
            • C canid

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

              Pl45m4P Offline
              Pl45m4P Offline
              Pl45m4
              wrote on last edited by
              #6

              @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
              0
              • C canid

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

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

                @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
                5
                • jsulmJ jsulm

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

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

                  @jsulm
                  Ok, got it. Thank you

                  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