Re: Inserting text in a text buffer using a callback function
- From: TORRI Vincent <Vincent Torri math u-bordeaux fr>
- To: Horror Vacui <horrorvacui gmx net>
- Cc: "gtk-app-devel-list gnome org" <gtk-app-devel-list gnome org>
- Subject: Re: Inserting text in a text buffer using a callback function
- Date: Sat, 2 Nov 2002 15:48:44 +0100 (CET)
On Sat, 2 Nov 2002, Horror Vacui wrote:
I have the following problem: while trying to learn GTK, I decided to
create a button that should insert text in a scrolled window (more
exactly: into a text buffer in a scrolled window). I created a callback
for a function, and it wouldn't work. I transferred parts of code from
the function to main (so that it is inserted during the realisation of
the window), and that did work. The function behaves weird: before, the
program would just segfault when this button is clicked, now it returns
a Gtk-critical message saying that assertion GTK_IS_TEXT_BUFFER (buffer)
for the argument I passed to the function failed (I don't understand
that change either - I didn't change anything of significance). From
what I learned from learning programming, the error is probably
something very trivial, but it can take me days to sort out. Here are
the significant parts of code:
GtkWidget *view;
GtkTextBuffer *buffer;
button=gtk_button_new_with_label("text"); /*the button*/
g_signal_connect(G_OBJECT (button), "clicked", G_CALLBACK (text),
buffer); /*connecting signal to callback*/
view=gtk_text_view_new();
buffer=gtk_text_view_get_buffer(GTK_TEXT_VIEW (view)); /*the buffer*/
gtk_text_buffer_set_text(buffer, "This is the text in the scrolled
window\n", -1); /*inserting text, this works*/
void text(GtkTextBuffer *buffer) /*the callback function*/
the prototype of the callback function associated to the "clicked" signal
is
void user_function (GtkButton *button, gpointer user_data)
(from the API). You don't "insert" text in the GtkTextBuffer (as you
could think), but in the GtkButton.
Hope this helps
Vincent TORRI
{
GtkTextIter iter;
gtk_text_buffer_get_iter_at_offset(buffer, &iter, 0);
gtk_text_buffer_insert(buffer, &iter, "This is the text in the
scrolled window\n", -1); /*this doesn't work*/
}
Of course, I've already run the code through a debugger. The callback
works, the function text is called with pointer "buffer" as argument, it
is the correct one, it is the correct type inside the function. Yet it
doesn't work. I've also tried using exactly the same function that works
in main (gtk_text_buffer_set_text()) in the callback function: nothing.
I also thought about a conflict between the two variables with the same
name "buffer" (which should hardly matter) and tried giving them
different names: nothing. I'm quite stuck, I hope someone can help.
Thanks in advance
Horror Vacui
_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
--
TORRI Vincent
Mathematiques Appliquees Bordeaux
Institut de Mathematiques
Universite Bordeaux 1
351 cours de la liberation
33 405 Talence cedex - France
Tel : 33 (0)5 57 96 21 42
Fax : 33 (0)5 56 84 26 26
--
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]