Variant


Description:

public Variant (string format, ...)

Creates a new Variant instance.

Think of this function as an analogue to to_string.

The type of the created instance and the arguments that are expected by this function are determined by format_string. See the section on GVariant format strings. Please note that the syntax of the format string is very likely to be extended in the future.

The first character of the format string must not be '*' '?' '@' or 'r'; in essence, a new Variant must always be constructed by this function (and not merely passed through it unmodified).

Note that the arguments must be of the correct width for their types specified in format_string. This can be achieved by casting them. See the GVariant varargs documentation.

MyFlags some_flags = FLAG_ONE | FLAG_TWO;
const gchar *some_strings[] = { "a", "b", "c", NULL };
GVariant *new_variant;

new_variant = g_variant_new ("(t^as)",
// This cast is required.
(guint64) some_flags,
some_strings);

Example: Create a new variant with a type string:

public static int main (string[] args) {
Variant var1 = new Variant ("(ssi)", "aa", "bb", 10);
string? val1 = null;
string? val2 = null;
int val3 = -1;

VariantIter iter = var1.iterator ();
iter.next ("s", &val1);
iter.next ("s", &val2);
iter.next ("i", &val3);

// Output: ``aa, bb, 10``
print ("%s, %s, %d\n", val1, val2, val3);

return 0;
}

valac --pkg glib-2.0 GLib.Variant.Variant.vala

Parameters:

...

arguments, as per format_string

format_string

a Variant format string

Returns:

a new floating Variant instance