GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Thu Aug 21, 2014 8:14 am

All times are UTC




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: Passing Window To Callback Function
PostPosted: Thu Aug 09, 2012 6:03 pm 
Offline
Familiar Face

Joined: Fri Aug 03, 2012 12:06 am
Posts: 5
I am trying to pass a window object to a callback function, delete everything in that window, and put new stuff in. No matter what I seem to do, when I pass the window into the callback, I get a segfault. Here is the current iteration of my code that now passes a struct to the callback.

Code:
#include <gtk/gtk.h>

typedef struct start_dialog_type {
   GtkWidget   *window;
   GtkWidget   *button;
   GtkWidget   *logo;
} StartDialog;



static void enter_main(GtkWidget *widget, GdkEventButton *event, gpointer data)
{
   GtkWidget   *box;
   GtkWidget   *button;
   GtkWidget   *window;

   gtk_widget_destroy(widget);

   box = gtk_hbox_new(FALSE, 10);
   
   button = gtk_button_new_with_label("Button1");
   gtk_box_pack_start(GTK_BOX(box), button, TRUE, TRUE, 0);
   gtk_widget_show(button);

   button = gtk_button_new_with_label("Button2");
   gtk_box_pack_start(GTK_BOX(box), button, TRUE, TRUE, 0);
   gtk_widget_show(button);

   button = gtk_button_new_with_label("Button3");
   gtk_box_pack_start(GTK_BOX(box), button, TRUE, TRUE, 0);
   gtk_widget_show(button);
   
   gtk_widget_show(box);
   
   window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
   gtk_container_set_border_width(GTK_CONTAINER(window),0);   
   gtk_window_set_default_size(GTK_WINDOW(window), 480, 270);

   gtk_window_set_type_hint(GTK_WINDOW(window),GDK_WINDOW_TYPE_HINT_SPLASHSCREEN);

   //gtk_container_add(GTK_CONTAINER(((StartDialog *) data)->window), box); //Doesn't work, throws a seg fault
   gtk_container_add(GTK_CONTAINER(window), box);
   gtk_widget_show(GTK_WINDOW(window));
   
   
}



int main (int argc, char *argv[])
{

   GdkCursor   *cur;
   StartDialog start;
   gtk_init (&argc, &argv);
   
/**********
* start.window
* *******/


   start.window = gtk_window_new(GTK_WINDOW_POPUP);

   gtk_container_set_border_width(GTK_CONTAINER(start.window),0);   

   gtk_window_set_default_size(GTK_WINDOW(start.window), 480, 270);


   gtk_window_set_type_hint(GTK_WINDOW(start.window),GDK_WINDOW_TYPE_HINT_SPLASHSCREEN);

   start.logo = gtk_image_new_from_file("./logo.png");
   gtk_widget_show(start.logo);

/**********
* start.button
* *******/

   start.button = gtk_button_new();

   g_signal_connect(start.button, "clicked", G_CALLBACK(enter_main), &start);

   gtk_container_add(GTK_CONTAINER(start.button), start.logo);
   gtk_widget_show(start.button);
   gtk_container_add(GTK_CONTAINER(start.window),start.button);

   
/**********
* Display and start event loop
* *******/

   gtk_widget_show (start.window);       

   cur = gdk_cursor_new(GDK_BLANK_CURSOR);
   gdk_window_set_cursor(gtk_widget_get_window(GTK_WIDGET(start.window)), cur); //Must be placed after the main window gets shown.
   gdk_cursor_unref(cur); //Removes cursor object from memory once it has been set

   gtk_main ();
                                        
   return 0;
}



I am currently cross-compiling this for an ARM board. Thank you for any help you can provide!


Top
 Profile  
 
 Post subject: Re: Passing Window To Callback Function
PostPosted: Thu Aug 09, 2012 7:21 pm 
Offline
Never Seen the Sunlight

Joined: Wed Jul 23, 2008 10:31 am
Posts: 2406
Location: Slovenia
Hi.

You're having troubles because GtkButton::clicked signal handler must have prototype:
Code:
void handler (GtkButton *button, gpointer data)


Try fixing that and I'm sure most of your troubles will go away.

Cheers,
Tadej


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 6 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group