How to store int64 value in GSettings?

170 views Asked by At

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?

1

There are 1 answers

0
apmasell On BEST ANSWER

You can use any Variant type. The type string for int64 is x. You can then use Variant.int64 to create a new variant and GLib.Settings.get_value and GLib.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 call set_value with a int64 and it will be automarshalled. Similarly, if you cast the return of get_value to int64, it will be unmarhsalled.