beaver-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Beaver-devel] beaver_box_prompt


From: t.heinzen
Subject: Re: [Beaver-devel] beaver_box_prompt
Date: Sun, 14 Sep 2008 00:37:33 +0200

Um Sat, 13 Sep 2008 21:59:17 +0200
 schrieb Double 12 <address@hidden>:
> Surprisingly, gtk_entry_get_text returns a *const*
> gchar*. 

Did not know that it is possible to return const variables.
obviously it is ^^

> This is because the function returns a pointer to
> a string that "points to internally allocated storage in
> the widget and must not be freed, modified or stored".
> I saved the result of the gtk_entry_get_text function in
> a const gchar* and used that as return value for the
> function beaver_box_prompt_impl.
> The weird thing is: if I print the text (extracted from
> the entry) directly in the beaver_box_prompt_impl
> function, it is displayed correctly. If I try to print
> the text in the  function it is called from
> (sample_clicked in sample.c), I get weird characters.
> You will see it it if you download the latest commits
> from the CVS and then compile.

Well it isn't that weird if you look at your statement
("points to internally allocated storage"). when you
destroy the widget (and this you probably do in
beaver_box_prompt_impl) then this internal storage is
freed. what you actually have to do is, is duplicating the
string into a "non-internal" space (aka. heap memory). this
you could do via g_strdup() (this returns a gchar* that has
to be freed). then it should work. 

greets
Tobias




reply via email to

[Prev in Thread] Current Thread [Next in Thread]