Re: Callback Question
- From: MatÃÂas Alejandro Torres <torresmat gmail com>
- To: Roman Makurin <drolyk gmail com>
- Cc: gtk-app-devel-list gnome org
- Subject: Re: Callback Question
- Date: Sun, 13 Apr 2008 23:38:49 -0300
Roman Makurin escribiÃ:
Ð ÐÑÐ, 13/04/2008 Ð 15:46 -0300, MatÃÂas Alejandro Torres ÐÐÑÐÑ:
Hi,
Can I call GTK Functions that modifies the GUI inside a callback?
Just an example:
/*CALLBACK*/
void text_to_upper_callback (GtkEntry *entry, gpointer data) {
/* I modify the GUI by setting the text of an entry */
gtk_entry_set_text (entry,
g_utf8_strup (gtk_entry_get_text
(entry), -1)));
}
void* init () {
[...]
g_signal_connect (entry, "activate", (GCallback)
text_to_upper_callback, NULL);
[...]
}
#include <gtk/gtk.h>
static void destroy(GtkWidget *widget, gpointer data) {
gtk_main_quit();
}
static void convert(GtkButton *button, GtkEntry *entry) {
gtk_entry_set_text(entry,
g_utf8_strup(gtk_entry_get_text(entry), -1));
}
int main(int argc, char **argv) {
GtkWidget *window, *entry, *button, *box;
gtk_init(&argc, &argv);
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window), "Converter");
gtk_container_set_border_width(GTK_CONTAINER(window), 10);
gtk_window_set_resizable(GTK_WINDOW(window), FALSE);
g_signal_connect(G_OBJECT(window), "destroy",
G_CALLBACK(destroy), NULL);
box = gtk_hbox_new(FALSE, 0);
entry = gtk_entry_new();
button = gtk_button_new_with_mnemonic("_Convert");
gtk_box_pack_start(GTK_BOX(box), entry, TRUE, TRUE, 0);
gtk_box_pack_start(GTK_BOX(box), button, FALSE, FALSE, 0);
g_signal_connect(G_OBJECT(button), "clicked",
G_CALLBACK(convert), entry);
gtk_container_add(GTK_CONTAINER(window), box);
gtk_widget_show_all(window);
gtk_main();
return 0;
}
_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Thank you all for this! Especialy for the long example, but, it was just
an example.
I've made an application that works perfectly on Linux but in Window$ it
crashes a lot!
I've been trying to find a solution (actually a clue of what the problem
might be) in any discussion I was able to find about GTK crashes in the
internet.
In one of these discussions it was said that gtk functions can't be
called inside callbacks, that it wasn't safe yet. That, if you call any
gtk function inside a callback, it should be done using
g_object_idle_add. Unfortunatly I didn't check the date of the
discussion, maybe, it is too old.
Thanks.
MatÃas.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]