Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Saving 64-bit integer with QSettings

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.

like image 944
Violet Giraffe Avatar asked Oct 25 '25 01:10

Violet Giraffe


2 Answers

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.

like image 122
Pavel Strakhov Avatar answered Oct 26 '25 17:10

Pavel Strakhov


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));
[..]
like image 35
vahancho Avatar answered Oct 26 '25 18:10

vahancho