Function

GLibVariantnew

Declaration

GVariant*
g_variant_new (
  const gchar* format_string,
  ...
)

Description

Creates a new GVariant instance.

Think of this function as an analogue to g_strdup_printf().

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][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 GVariant 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][gvariant-varargs].

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);
Available since:2.24

Parameters

format_string const gchar*
 

A GVariant format string.

 The data is owned by the caller of the function.
 The string is a NUL terminated UTF-8 string.
... none
 

Arguments, as per format_string.

Return value

Returns: GVariant
 

A new floating GVariant instance.

 The caller of the function takes ownership of the data, and is responsible for freeing it.