Problem with signals..




The problem is that for some reason, clicking on any button causes a
sigsegv.  I know there is something wrong with the code that is causing
it, but for the life of me can't figure out what it is.  I am fairly new
to gtk (Installed it this morning for the first time. :P ), so it may very
well be something very simple.

Any help would be greatly appreciated.  Oh.. And I have joined the list,
or at least sent a request to it, but have had no responce back from the
daemon yet, so please respond to oswell@mail.ocis.net.

Thanks again..

-------

Here is my system:
    OpenBSD envy 2.2 GENERIC#10 i386

    gtk-config --version
         0.99.10


Here is the output from running my program:

oswell@envy [~/code/configsys]: ./configsys 
Trace/BPT trap (core dumped)
oswell@envy [~/code/configsys]: ./configsys 

** ERROR **: sigsegv caught


The first error I had never seen before I went to capture an error for
this email... Whacky. :)


And at last.. Here is the code.

----------
#include "gtk/gtk.h"

int login (void)
{
    g_print("You pushed login.\n");
}

void destroy (void)
{
  gtk_exit (0);
}

void new_alias(GtkWidget *widget, gpointer *data)
{
   g_print("Clicked on new_alias: %s\n", (char *)data);
}


/******************************/
/* Print out the main screen. */
/******************************/
GtkWidget *printMain(void)
{
  GtkWidget *window, *table;
  GtkWidget *new_alias;

  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_signal_connect (GTK_OBJECT (window), "destroy", GTK_SIGNAL_FUNC (destroy), NULL);
  gtk_window_set_title(GTK_WINDOW (window), "On Call Internet Services - User Configuration");
  gtk_container_border_width (GTK_CONTAINER (window), 10);
 
  /* Create a new table. */
  table = gtk_table_new(4,6,1);
  gtk_container_add(GTK_CONTAINER(window), table);

   /* Create the newalias button */
  new_alias = gtk_button_new_with_label ("New Alias");
  gtk_signal_connect(GTK_OBJECT(new_alias), "clicked", GTK_SIGNAL_FUNC (new_alias), (gpointer) "New Alias");
  gtk_table_attach_defaults(GTK_TABLE(table), new_alias, 0,1,0,1);
  gtk_widget_show(new_alias);

  gtk_widget_show (table);
  gtk_widget_show (window);

  return(window); 
}


/*******************************/
/* dologin shows login screen. */
/*******************************/

int dologin(void)
{
    GtkWidget *window, *table;
    GtkWidget *login, *cancel;
    GtkWidget *label, *username, *password;

    window = gtk_window_new(GTK_WINDOW_DIALOG);
    gtk_signal_connect (GTK_OBJECT (window), "destroy", GTK_SIGNAL_FUNC (destroy), NULL);

    gtk_window_set_title(GTK_WINDOW(window), "Login Dialog");
    gtk_container_border_width (GTK_CONTAINER (window), 10);
    gtk_window_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);

    /* Create table in new dialog box. */
    table = gtk_table_new(4,6,1);
    gtk_container_add(GTK_CONTAINER(window), table);
   
    /* Create username label. */
    label = gtk_label_new("Username:  ");
    gtk_table_attach_defaults(GTK_TABLE(table), label, 1, 2, 0, 1);
    gtk_widget_show(label);

    /* Create username text box. */
    username = gtk_entry_new_with_max_length(15);
    gtk_table_attach_defaults(GTK_TABLE(table), username, 2, 5, 0 , 1);
    gtk_widget_show(username);

    /* Create password label. */
    label = gtk_label_new("Password:  ");
    gtk_table_attach_defaults(GTK_TABLE(table), label, 1, 2, 1, 2);
    gtk_widget_show(label);

    /* Create password text box. */
    password = gtk_entry_new_with_max_length(15);
    gtk_table_attach_defaults(GTK_TABLE(table), password, 2, 5, 1 , 2);
    gtk_widget_show(password);

    /* Create the login button */
    login = gtk_button_new_with_label ("Login");
    gtk_signal_connect(GTK_OBJECT(login), "clicked", GTK_SIGNAL_FUNC(login), NULL);
    gtk_table_attach_defaults(GTK_TABLE(table), login, 1,2,3,4);
    gtk_widget_show(login);

    /* Create the cancel button */
    cancel = gtk_button_new_with_label ("Cancel");
    gtk_signal_connect(GTK_OBJECT(cancel), "clicked", GTK_SIGNAL_FUNC(destroy), NULL);
    gtk_table_attach_defaults(GTK_TABLE(table), cancel, 4,5,3,4);
    gtk_widget_show(cancel);

    /* Make the login button the default. */
    GTK_WIDGET_SET_FLAGS(login, GTK_CAN_DEFAULT);
   
    gtk_widget_show (table);
    gtk_widget_show (window);
   
    return(0);
}

int
main (int argc, char **argv)
{ GtkWidget *window;
  int login = 0;

  gtk_init (&argc, &argv);

  window = printMain();
  login = dologin();

  gtk_main ();

  return 0;
}




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