Re: [gtk-list] Swapping label text?
- From: "Emmanuel DELOGET" <pixel epita fr>
- To: <gtk-list redhat com>
- Subject: Re: [gtk-list] Swapping label text?
- Date: Thu, 29 Jul 1999 18:32:57 +0200
>Could someone help me. This is driving me crazy...
>
>I need a dead simple bit of code that take two GtkLabels and swaps the
>text from one to the other, and vice versa.
> [snipped]
>i.e. the label text moves from the second to the first, but this doesn't
>work in the reverse direction.
>
>Here's the code:
>-------------------------------------------------------
> gchar *tt;
> gchar *ss;
>
> gtk_label_get (GTK_LABEL (label1), (gchar **) & tt);
> gtk_label_get (GTK_LABEL (label2), (gchar **) & ss);
You get the pointer... right. tt contains the address of the
label string
>
> gtk_label_set (GTK_LABEL (label1), (gchar *) ss);
The label string in label1 is destroyed.
> gtk_label_set (GTK_LABEL (label2), (gchar *) tt);
And since tt points on it, tt now contains garbage...
What you can do is:
gchar *tt, *ss;
gtk_label_get(GTK_LABEL(label1), &tt);
tt = strdup(tt);
gtk_label_get(GTK_LABEL(label2), &ss);
gtk_label_set_text(GTK_LABEL(label1), ss);
gtk_label_set_text(GTK_LABEL(label2), tt);
free(tt);
BTW, you don't need to cast &xx to (gchar **), since
&xx IS a gchar **.
Yours,
pixel@epita.fr
>--------------------------------------------------------
>Tom.
>--
> .-------------------------------------------------------.
> .^. | Tom Gilbert, England | tom@tomgilbert.freeserve.co.uk |
> /V\ |----------------------| www.tomgilbert.freeserve.co.uk |
> // \\ | Sites I recommend: `--------------------------------|
> /( )\ | www.freshmeat.net www.enlightenment.org www.gnome.org |
> ^^-^^ `-------------------------------------------------------'
>
>--
>To unsubscribe: mail -s unsubscribe gtk-list-request@redhat.com < /dev/null
>
>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]