Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. General talk
  3. Brainstorm
  4. [5.5.1] QVariant Support for Long Double
Forum Updated to NodeBB v4.3 + New Features

[5.5.1] QVariant Support for Long Double

Scheduled Pinned Locked Moved Unsolved Brainstorm
2 Posts 2 Posters 2.3k 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.
  • Q Offline
    Q Offline
    QtBit44
    wrote on last edited by
    #1

    Hi,

    I recently discovered that QVariant does not support the long double format. The source code I'm using requires the use of the QVariant class for data types. I am dealing with numbers that go down to the 10^-9 degree, so using floats or ordinary doubles won't help me much with precision. Can anyone help me out with one of the following things:

    1. If someone has already solved this problem, can that someone forward the code to me?
    2. A workaround to this problem that does not instigate a loss of data precision.
    3. Can someone instruct me (or point me in the right direction) on how to modify the QVariant class so that is has long double support (or educate me on the inner workings of the class)?

    Thanks.

    1 Reply Last reply
    0
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by
      #2

      QVariant supports any type of data. You don't need to modify the class. You just need to register your type.

      In some header register the type:

      Q_DECLARE_METATYPE(long double)
      

      and then you can use it:

      long double foo = 42.0;
      QVariant bar = QVariant::fromValue(foo);     //put value into variant
      long double bazz = bar.value<long double>(); //and get it back
      

      If you also want to serialize/deserialize your variants you'll need to implement and register stream operators for it: qRegisterMetaTypeStreamOperators().

      1 Reply Last reply
      4

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved