I am using GSettings in my Vala application to store some data. And one of my fields should store date. And all functions in Vala that manage date and time return int64 value.
I know how to store int values in GSettings schema, but I want to do it without converting int64 to int.
I know it's not a problem nowadays and I can safely convert int64 DateTime
to int, but someday it will overflow and won't work correctly.
So, the question: is storing int64 in GSettings possible? And if yes, how?
You can use any
Variant
type. The type string forint64
isx
. You can then useVariant.int64
to create a new variant andGLib.Settings.get_value
andGLib.Settings.set_value
to manipulate it.Vala can also marshal
Variant
types automatically in most cases. If your schema is set correctly, you can simply callset_value
with aint64
and it will be automarshalled. Similarly, if you cast the return ofget_value
toint64
, it will be unmarhsalled.