GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Wed Sep 17, 2014 5:33 am

All times are UTC




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Multiple toplevel windows problem
PostPosted: Tue Mar 10, 2009 8:16 pm 
Offline
Familiar Face

Joined: Tue Mar 03, 2009 6:03 pm
Posts: 15
Hi all,

I'm trying to make a program with 2 toplevel windows. With below code it somewhat works. After I launch the program, if I click on the preferences button it shows me the preferences window, but after I close the latter clicking on the preferences button does not show the preferences window anymore and just returns this error in the terminal:

[code=]Gtk-CRITICAL **: gtk_widget_show_all: assertion `GTK_IS_WIDGET (widget)' failed [/code]

Many thanks for any help in advance,
Rouslan

Code:
/* Create preference window */
   pref_window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
   gtk_window_set_resizable (GTK_WINDOW (pref_window), FALSE);
   gtk_widget_set_size_request (pref_window, 400, 250);


   g_signal_connect (GTK_OBJECT (pref_window), "destroy",
           G_CALLBACK (gtk_widget_destroy), pref_window);

   gtk_window_set_title (GTK_WINDOW (pref_window), "Preferences");
   gtk_container_set_border_width (GTK_CONTAINER (pref_window), 0);

   vbox = gtk_vbox_new (FALSE, 0);
   gtk_container_add (GTK_CONTAINER (pref_window), vbox);


/* Create main window */
   window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
   gtk_window_set_resizable (GTK_WINDOW (window), FALSE);
   gtk_widget_set_size_request (window, 800, 700);


   g_signal_connect (GTK_OBJECT (window), "destroy",
           G_CALLBACK (gtk_main_quit), NULL);

    gtk_widget_show (window);

   gtk_window_set_title (GTK_WINDOW (window), "Main window");
   gtk_container_set_border_width (GTK_CONTAINER (window), 0);

   hbox = gtk_hbox_new (FALSE, 0);
   gtk_container_add (GTK_CONTAINER (window), hbox);

// here goes the rest of the code

   config_button = gtk_button_new_from_stock (GTK_STOCK_PREFERENCES);
   g_signal_connect (GTK_OBJECT (config_button), "clicked",
              G_CALLBACK (show_prefs), NULL);
   gtk_box_pack_start (GTK_BOX (vbox), config_button, TRUE, TRUE, 5);



The callback:
Code:
void show_prefs() {
   gtk_widget_show_all (pref_window);
}


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 10, 2009 9:33 pm 
Offline
Never Seen the Sunlight

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

The problem you're experiencing is caused by the destruction of the preferences window. When you click close button, preference window is destroyed.

To avoid this problem, replace these two lines:
Code:
   g_signal_connect (GTK_OBJECT (pref_window), "destroy",
             G_CALLBACK (gtk_widget_destroy), pref_window);
with these two:
Code:
   g_signal_connect (GTK_OBJECT (pref_window), "delete-event",
             G_CALLBACK (gtk_widget_hide_on_delete), NULL);

Docs: http://library.gnome.org/devel/gtk/stable/GtkWidget.html#gtk-widget-hide-on-delete


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 11, 2009 12:45 am 
Offline
Familiar Face

Joined: Tue Mar 03, 2009 6:03 pm
Posts: 15
Many thanks, tadeboro. It worked perfectly :D

Rouslan


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

All times are UTC


Who is online

Users browsing this forum: No registered users and 2 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:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group