Is there any neat way, short of converting number to QByteArray
, to save quint64
with QSettings
? The problem is QVariant
doesn't accept qint64
nor quint64
.
Asked
Active
Viewed 5,807 times
3 Answers
11
QVariant
supports qlonglong
and qulonglong
. As the documentation says, these are the same as qint64
and quint64
. So you can just use QVariant::QVariant(qlonglong)
and QVariant::toLongLong
.

Pavel Strakhov
- 39,123
- 5
- 88
- 127
1
What if you store qint64
as a string. QString supports such conversion: QString::number(qlonglong n, int base)
, where qlonglong
is the same as qint64
. The same for quint64
- use QString::number(qulonglong n, int base)
, where qulonglong
is the same as quint64
.
QSettings settings("config.ini", QSettings::IniFormat);
[..]
qint64 largeNumber = Q_INT64_C(932838457459459);
settings.setValue("LargeNumber", QString::number(largeNumber));
[..]

vahancho
- 20,808
- 3
- 47
- 55
-
1There's also a QVariant ctor that takes qlonglong – Frank Osterfeld Sep 24 '13 at 08:26
0
Another solution is to realize that IEEE 754 double format has a 53 bit fraction (don't forget the implicit 53rd bit!) and a sign bit. This allows you to store unsigned 53 bit integers without loss of precision, or signed 54 bit integers. You can store if:
- your qint64's absolute value is smaller than 2^55, or
- your quint64 is smaller than 2^54.

Kuba hasn't forgotten Monica
- 95,931
- 16
- 151
- 313