cgtk3gtktextview

adding number to GtkTextBuffer in gtk+3


how can we add a number of type gint to a TextBuffer in gtk+3? gtk_text_buffer_set_text has argument of type gchar but I want to set integer of type gint


Solution

  • You cannot show an integer value directly. You must first format the integer value in a character buffer and set this as the text

    GtkTextBuffer *textbuf;
    char cbuf[15];
    int n, v;
    v = 738;
    n = sprintf(cbuf, "%d", v);
    gtk_text_buffer_set_text(textbuf, cbuf, n);