g_signal_connect isn't working
- From: Pier-Luc Charbonneau <pierluc charbonneau gmail com>
- To: gtk-app-devel-list gnome org
- Subject: g_signal_connect isn't working
- Date: Thu, 10 Mar 2005 21:12:43 -0500
Hi,
I'm trying to write my first gtk+ app and this snippet isn't working
(tried on 2 different computer and I tried to upgrade to the latest
gtk+)
When pressing a key in the entry:
where is psi : 134520912
where is data: 135602024
psistart *psi : 514
psistart *data: 8
When pushing the button:
where is psi : 134520912
where is data: 134520912
psistart *psi : 514
psistart *data: 514
here is the code:
#include <gtk/gtk.h>
typedef struct{
int psistart;
int psiend;
int psidiff;
}PSI;
PSI *psi;
static gboolean delete_event (GtkWidget *widget, GdkEvent *event, gpointer data)
{
gtk_main_quit();
return FALSE;
}
static gboolean recalculate_psi_consumption(GtkWidget *widget, gpointer data)
{
PSI *psi2;
psi2 = (PSI *) data;
g_print("where is psi : %i\n",psi);
g_print("where is data: %i\n",(PSI *)data);
g_print("psistart *psi : %i\n",((PSI*)psi)->psistart);
g_print("psistart *data: %i\n\n\n",((PSI*)data)->psistart);
}
int main(int argc, char *argv[])
{
psi = g_new(PSI,1);
psi->psistart=514;
gtk_init (&argc, &argv);
GtkWidget *window;
GtkWidget *button;
GtkWidget *start;
GtkWidget *table;
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
g_signal_connect (G_OBJECT (window), "delete_event",G_CALLBACK
(delete_event), NULL);
button = gtk_button_new_with_label("Hi!");
table = gtk_table_new (2, 1, FALSE);
gtk_container_add(GTK_CONTAINER(window),table);
gtk_table_attach_defaults(GTK_TABLE(table),button,0,1,0,1);
gtk_table_attach_defaults(GTK_TABLE(table),start = gtk_entry_new(),1,2,0,1);
g_signal_connect(G_OBJECT(start),"key_press_event",G_CALLBACK(recalculate_psi_consumption),(gpointer)psi);
g_signal_connect(G_OBJECT(button),"clicked",G_CALLBACK(recalculate_psi_consumption),(gpointer)psi);
gtk_widget_show_all (window);
gtk_main ();
return 0;
}
I'm working on this bug for 9 hours I can't see why the button and the
entry are not showing the same g_print result... Crying or Very sad
My last resort is that it is a bug in gtk+ but since I'm new to gtk+ I
don't think so... (Am I wrong?)
Thank you and sorry about my english I've been coding for so long my
brain is dead,
IcyWolf
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]