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. Value instead of .toFloat
Qt 6.11 is out! See what's new in the release blog

Value instead of .toFloat

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 2 Posters 1.1k 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.
  • N Offline
    N Offline
    NotYourFan
    wrote on last edited by
    #1

    Hey i have the following code:

    QVariant x = .......;
    
    return x.toFloat();
    

    I read the x AND the type from a JSON-File.
    So i wanted very dynamically, i search something like
    pseudocode:

    QVariant x = .....; 
    return x.type(type read from the JSON-File as a String);
    

    Do you have a possibility where i can set the type as a String ?

    aha_1980A 1 Reply Last reply
    0
    • N NotYourFan

      Hey i have the following code:

      QVariant x = .......;
      
      return x.toFloat();
      

      I read the x AND the type from a JSON-File.
      So i wanted very dynamically, i search something like
      pseudocode:

      QVariant x = .....; 
      return x.type(type read from the JSON-File as a String);
      

      Do you have a possibility where i can set the type as a String ?

      aha_1980A Offline
      aha_1980A Offline
      aha_1980
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @NotYourFan

      return x.type(type read from the JSON-File as a String);

      How should that work? Your function needs a definite return type, so you cannot decide within the function what you want to return.

      You can of course, convert the variant to a string always...

      Qt has to stay free or it will die.

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

        Hey @aha_1980,

        i think there is a way with "type" ... but i dont know exactly.

        I want to set the type dynamically ....

        But thank you for your request

        aha_1980A 1 Reply Last reply
        0
        • N NotYourFan

          Hey @aha_1980,

          i think there is a way with "type" ... but i dont know exactly.

          I want to set the type dynamically ....

          But thank you for your request

          aha_1980A Offline
          aha_1980A Offline
          aha_1980
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @NotYourFan said in Value instead of .toFloat:

          i think there is a way with "type" ... but i dont know exactly.

          No, in C++ this is not possible. That's why variants exist in the first place.

          Qt has to stay free or it will die.

          1 Reply Last reply
          1
          • N Offline
            N Offline
            NotYourFan
            wrote on last edited by
            #5

            @aha_1980
            thx, i solved my problem now with regex :)

            aha_1980A 1 Reply Last reply
            0
            • N NotYourFan

              @aha_1980
              thx, i solved my problem now with regex :)

              aha_1980A Offline
              aha_1980A Offline
              aha_1980
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @NotYourFan Then please mark this topic as SOLVED too. Thanks!

              Qt has to stay free or it will die.

              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