Re: GTK question


Subject: Re: GTK question
From: Aaron Lehmann (aaronl@vitelus.com)
Date: Wed Feb 16 2000 - 19:15:36 CST


On Wed, 16 Feb 2000 sterwill@abisource.com wrote:

> sam th wrote:
> > In implementing the Word Count dialog, I obviously need to display some
> > numbers that are going to be stored as integers. I am currently looking
> > at the GTK tutorial, and I am unable to find someplace that tells me how
> > to display an integer the same way I would use a label to display a
> > string. I suspect that the answer to this is fairly obvious, but I have
> > yet to find it. Thanks in advance
>
> To GTK, it's all just a gchar string. If you need to display an integer in a
> label, convert it to a string with a printf-like function. Something
> like the following will get you a label with the number in it.
>
> UT_uint32 nWordCount; // this is the integer value from
> // some XP word counting process in
> // AbiWord, it has a value like 2033
>
> char string[128]; // enough to store a very large number
>
> g_snprintf(string, 128, "%d", nWordCount);
>
> GtkWidget * numberLabel = gtk_label_new(string);
> UT_ASSERT(numberLabel);
>
> gtk_widget_show(numberLabel);
>
> /* code follows to stick numberLabel in the dialog, etc. */

May I take this oportunity to plug g_strdup_printf()? This function will
automatically return a char* to allocated memory of the right size filled
with whatever you have specified in the args. Beats fixed-size buffers
like this any day IMHO. It's worth looking it up in the docs. Don't forget
to free the pointer you get back!

> --
> Shaw Terwilliger
>
>



This archive was generated by hypermail 2b25 : Wed Feb 16 2000 - 19:15:59 CST