LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   GTK-Critical error compiling a smart program (with menu) (https://www.linuxquestions.org/questions/programming-9/gtk-critical-error-compiling-a-smart-program-with-menu-732182/)

clarci 06-11-2009 06:44 AM

GTK-Critical error compiling a smart program (with menu)
 
Hi
First time sorry for my english is not soo good, i try to compile the next source :

Code:

#include <gtk/gtk.h>
#include <glib.h>

gint destroyapp (GtkWidget *widget, gpointer gdata)
{
 gtk_main_quit();
 return (FALSE);
}
/*------------------------------------------------------------------*/
gint ClosingAppWindow (GtkWidget *widget, gpointer gdata)
{
gtk_main_quit();
 return (FALSE);
}
/*------------------------------------------------------------------*/
/*------------------------------------------------------------------*/
int main (int argc, char *argv[])
{
 GtkWidget *window;
 GtkWidget *vbox;
 GtkWidget *menuFile = NULL;
 GtkWidget *menubar = NULL;
 GtkWidget *menu = NULL;
 GtkWidget *menuitem = NULL;

 gtk_init (&argc, &argv);
 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
 gtk_signal_connect(GTK_OBJECT(window),"delete_event",GTK_SIGNAL_FUNC(destroyapp), NULL);
 vbox = gtk_vbox_new(FALSE,0);
 
 gtk_container_add(GTK_CONTAINER(window), vbox);
 gtk_window_set_default_size (GTK_WINDOW(window), 640, 200);

 /*FILE MENU*/
 menuFile = gtk_menu_item_new_with_label("File");
 gtk_menu_bar_append (GTK_MENU_BAR(menubar), menuFile);
 menu= gtk_menu_new();
 gtk_menu_item_set_submenu(GTK_MENU_ITEM(menuFile), menu);
 /*FILE MENU*/


 gtk_widget_show (vbox);
 gtk_widget_show (menu);
 gtk_widget_show (menuitem);
 gtk_widget_show (menubar);
 gtk_widget_show (window);
 gtk_widget_show(menuFile);

 gtk_main();
 return 0;
}

with commands:
g++ -Wall -g -c fdialog.c -export-dynamic `pkg-config --cflags --libs gtk+-2.0` `gtk-config --cflags` `gtk-config --libs`

g++ -o fdialog fdialog.o `pkg-config --cflags --libs gtk+-2.0` `gtk-config --cflags` `gtk-config --libs`

and it compile without errors, but when i try to run it, it can be run without menubar, and become this error message:

(fdialog:6369): Gtk-CRITICAL **: gtk_menu_shell_insert: assertion `GTK_IS_MENU_SHELL (menu_shell)' failed

(fdialog:6369): Gtk-CRITICAL **: gtk_widget_show: assertion `GTK_IS_WIDGET (widget)' failed

(fdialog:6369): Gtk-CRITICAL **: gtk_widget_show: assertion `GTK_IS_WIDGET (widget)' failed



is this a bug ? or how can i resolve this problem? maybe someone had the same problem.

Thanks for your help !
Robert

kike_coello 06-18-2009 03:58 PM

first of all, you have to add widgets to your boxes and then add the boxes to the final window, that's the last thing you gotta do when setting up your gui.

then you have to show only your window, which holds all your widgets, above you are showing all widgets independently.

lastly, i don't think you've added the menu widget to your window, so that might be the problem, you have declared and initialized it, but have not added to the gui.

i will post again after i have tried this myself when i get home.

hope that helps temporarily.

Enrique


All times are GMT -5. The time now is 05:09 AM.