g_signal_connect, structs and my sanity
- From: "beginner.c" <beginner c gmail com>
- To: gtk-app-devel-list gnome org
- Subject: g_signal_connect, structs and my sanity
- Date: Mon, 3 Nov 2008 12:45:15 -0800 (PST)
I'm getting a segfault on the gtkscale callback (when accessing printf("Qs:
%i\n", base->sTestOne.a);). Can somebody please tell me what I'm doing
wrong. Also, what would be the cleanest way to prototype my struct (struct
allStructs) outside of main?
Thanks
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <string.h>
#include <stdio.h>
#include <config.h>
#include <gtk/gtk.h>
#include "struct.h"
#include "cb.h"
/*
* Standard gettext macros.
*/
#ifdef ENABLE_NLS
# include <libintl.h>
# undef _
# define _(String) dgettext (PACKAGE, String)
# ifdef gettext_noop
# define N_(String) gettext_noop (String)
# else
# define N_(String) (String)
# endif
#else
# define textdomain(String) (String)
# define gettext(String) (String)
# define dgettext(Domain,Message) (Message)
# define dcgettext(Domain,Message,Type) (Message)
# define bindtextdomain(Domain,Directory) (Domain)
# define _(String) (String)
# define N_(String) (String)
#endif
#include "callbacks.h"
/* For testing propose use the local (not installed) glade file */
/* #define GLADE_FILE
PACKAGE_DATA_DIR"/struct_callback/glade/struct_callback.glade" */
#define GLADE_FILE "struct_callback.glade"
void funcScale (GtkWidget *widget, struct allStructs *base)
{
gdouble value;
value = gtk_range_get_value (GTK_RANGE (widget));
printf("Qs: %i\n", value);
printf("Qs: %i\n", base->sTestOne.a);
}
void button_callback (GtkButton *button, struct allStructs *base)
{
//base->sTestOne.a = 99;
printf("Qs: %i\n", base->sTestOne.a);
}
void button_callback2 (GtkButton *button, struct allStructs *base)
{
printf("Qs: %i\n", base->sTestOne.a);
}
int
main (int argc, char *argv[])
{
struct sOne
{
int a;
};
struct sTwo
{
int b;
};
struct widgets
{
GtkWidget *window;
GtkWidget *button;
GtkWidget *hscale;
GladeXML *gxml;
};
struct allStructs
{
struct widgets sWidgets;
struct sOne sTestOne;
struct sTwo sTestTwo;
};
struct allStructs base;
base.sTestOne.a = 967;
#ifdef ENABLE_NLS
bindtextdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR);
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
textdomain (GETTEXT_PACKAGE);
#endif
gtk_set_locale ();
gtk_init (&argc, &argv);
base.sWidgets.gxml = glade_xml_new (GLADE_FILE, NULL, NULL);
glade_xml_signal_autoconnect (base.sWidgets.gxml);
base.sWidgets.window = glade_xml_get_widget (base.sWidgets.gxml, "window");
base.sWidgets.button = glade_xml_get_widget (base.sWidgets.gxml,
"button1");
base.sWidgets.hscale = glade_xml_get_widget (base.sWidgets.gxml,
"hscale1");
g_signal_connect (base.sWidgets.button, "clicked", G_CALLBACK
(button_callback), &base);
g_signal_connect (base.sWidgets.button, "clicked", G_CALLBACK
(button_callback2), &base);
g_signal_connect (base.sWidgets.hscale, "change-value", G_CALLBACK
(funcScale), &base);
gtk_widget_show (base.sWidgets.window);
gtk_main ();
return 0;
}
--
View this message in context:
http://www.nabble.com/g_signal_connect%2C-structs-and-my-sanity-tp20310462p20310462.html
Sent from the Gtk+ - Apps Dev mailing list archive at Nabble.com.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]