Gio.Icon.to_string

### Method

# Gio Iconto_string

since: 2.20

#### Declaration

    gchar*
    g_icon_to_string (
      GIcon* icon
    )

#### Description

Generates a textual representation of `icon` that can be used for serialization such as when passing `icon` to a different process or saving it to persistent storage. Use `g_icon_new_for_string()` to get `icon` back from the returned string.

The encoding of the returned string is proprietary to `GIcon` except in the following two cases

- If `icon` is a `GFileIcon`, the returned string is a native path (such as `/path/to/my icon.png`) without escaping if the `GFile` for `icon` is a native file. If the file is not native, the returned string is the result of `g_file_get_uri()` (such as `sftp://path/to/my%20icon.png`).

- If `icon` is a `GThemedIcon` with exactly one name and no fallbacks, the encoding is simply the name (such as `network-server`).

Available since: 2.20

#### Return value

Type: `gchar*`

An allocated NUL-terminated UTF8 string or `NULL` if `icon` can’t be serialized. Use `g_free()` to free.

The caller of the method takes ownership of the data, and is responsible for freeing it.
The return value can be `NULL`.
The value is a NUL terminated UTF-8 string.