Strangely enough, it runs with no segfault on my system... ?
I did not change a single line!
by the way, GtkItemFactory has been deprecated..
On Thu, 2005-11-10 at 20:09 +0100, Luka Napotnik wrote:
> Hi.
>
> I'm writing a multithreaded GTK+ program and have a problem. The program
> segfaults at line:
> window_main->this = gtk_window_new(GTK_WINDOW_TOPLEVEL);
> What's wrong here?
>
> Greets,
> Luka
>
> The code:
> ============================================
> #include <stdio.h>
> #include <gtk/gtk.h>
>
> /* The main window's menu items. */
> GtkItemFactoryEntry window_main_menu_items[] = {\
> { "/File", NULL, NULL, 0, "<Branch>" },
> { "/File/Quit", NULL, NULL, 0, "<Item>" },
> { "/Help", NULL, NULL, 0, "<Branch>" },
> { "/Help/Manual", NULL, NULL, 0, "<Item>" },
> { "/Help/About", NULL, NULL, 0, "<Item>" }
> };
>
> struct _window_main {
> GtkWidget *this;
> GtkWidget *box_main, *box_content;
> GtkWidget *button_exit;
> GtkWidget *menubar;
> GtkWidget *toolbar;
> GtkWidget *label_start;
> GtkWidget *toolbar_start;
> };
>
> struct _window_main *window_main;
>
> /* This function code is copied from the GTK+ tutorial (www.gtk.org). */
> static GtkWidget *get_menubar_menu( GtkWidget *window )
> {
> GtkItemFactory *item_factory;
> GtkAccelGroup *accel_group;
> static gint nmenu_items = sizeof (window_main_menu_items) /
> sizeof (window_main_menu_items[0]);
>
> /* Make an accelerator group (shortcut keys) */
> accel_group = gtk_accel_group_new ();
>
> /* Make an ItemFactory (that makes a menubar) */
> item_factory = gtk_item_factory_new (GTK_TYPE_MENU_BAR, "<main>",
> accel_group);
>
> /* This function generates the menu items. Pass the item factory,
> the number of items in the array, the array itself, and any
> callback data for the the menu items. */
>
> gtk_item_factory_create_items (item_factory, nmenu_items,
> window_main_menu_items, NULL);
>
> /* Attach the new accelerator group to the window. */
> gtk_window_add_accel_group (GTK_WINDOW (window), accel_group);
>
> /* Finally, return the actual menu bar created by the item factory. */
> return gtk_item_factory_get_widget (item_factory, "<main>");
> }
>
> gpointer thread_func(gpointer data)
> {
> g_print("Js sm pa thread");
> }
>
> void window_main_init()
> {
> window_main = g_malloc(sizeof(*window_main));
> window_main->this = gtk_window_new(GTK_WINDOW_TOPLEVEL);
> gtk_window_set_title(GTK_WINDOW(window_main->this), "simos86");
> gtk_window_set_default_size(GTK_WINDOW(window_main->this), 600, 500);
>
>
> window_main->box_main = gtk_vbox_new(FALSE, 1);
>
> window_main->menubar = get_menubar_menu(window_main->this);
> gtk_box_pack_start(GTK_BOX(window_main->box_main),
> window_main->menubar, FALSE, FALSE, 1);
>
> window_main->toolbar = gtk_toolbar_new();
> gtk_toolbar_append_item(GTK_TOOLBAR(window_main->toolbar), "Start",
> "Start simulation", "None", NULL, NULL, NULL);
> gtk_box_pack_start(GTK_BOX(window_main->box_main),
> window_main->toolbar, FALSE, FALSE, 1);
>
> gtk_container_add(GTK_CONTAINER(window_main->this),
> window_main->box_main);
> }
> int main(int argc, char **argv)
> {
> gtk_init(&argc, &argv);
> GThread *thread1;
> g_thread_init(NULL);
> window_main_init();
>
>
> gtk_widget_show_all(GTK_WIDGET(window_main->this));
> thread1 = g_thread_create(thread_func, NULL, FALSE, NULL);
> gtk_main();
>
> return 0;
> }
_______________________________________________
gtk-app-devel-list mailing list
[email protected]
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list