[5.5.1] QVariant Support for Long Double
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:
- If someone has already solved this problem, can that someone forward the code to me?
- A workaround to this problem that does not instigate a loss of data precision.
- 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)?
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:
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().