Segfault and cheep mend of gtk_combo_box_get_active_text



Dear Matthias,

  Below is a simple program where gtk_combo_box_get_active_text
creates a segfault, as well as my (hacking) way of mending it.
Two other persons from gtk-app-devel-list gnome org compiled
it and got no segfault while running. So I rebuilt my system ??

With
pango 1.8.1 in /opt/gnome/share/pango-1.8.1/
atk 1.9.0 in /opt/gnome/share/atk-1.9.0/
gtk+ 2.6.7 in /opt/gnome/share/gtk+-2.6.7/

in this order, all three via
      make uninstall
      ./configure -prefix=/usr
      make
      make install
and made things tidy (I hope) by running
ldconfig while in /usr/lib. But same result.

Hope that will help you -- and not overcrowed your mbox :-).
Best, and thanks for your work!
Best,
Amities,
         Olivier

(Copy to gtk-app-devel-list gnome org for archiving).
-------------Complete and Minimal example------------
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <gtk/gtk.h>
GtkWidget *window, *my_combo_box;

void my_gtk_widget_destroy(GtkWidget *widget)
{
    gtk_widget_destroy(widget);
    gtk_main_quit();
}

void selecter(GtkComboBox *combo)
{
    gchar *name;

    if ((name = gtk_combo_box_get_active_text
                 (GTK_COMBO_BOX(my_combo_box))) == NULL){
        printf("What are we doing in here ???");
    } else {
       printf("Ok %s \n", name);};
}

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

    gtk_init (&argc, &argv);
    window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
    g_signal_connect(G_OBJECT(window), "destroy",
                     G_CALLBACK(my_gtk_widget_destroy), NULL);
    my_combo_box = gtk_combo_box_new_text();
    gtk_combo_box_append_text(GTK_COMBO_BOX(my_combo_box), "Oui");
    gtk_combo_box_append_text(GTK_COMBO_BOX(my_combo_box), "Non");
    /*gtk_combo_box_set_active(GTK_COMBO_BOX (my_combo_box),0);*/
    g_signal_connect (G_OBJECT(my_combo_box), "changed",
                      G_CALLBACK (selecter), NULL);
    gtk_container_add(GTK_CONTAINER(window), my_combo_box);
    gtk_widget_show_all(window);
    gtk_main();

    return 0;
}

/*
gcc -Wall -pedantic essai.c -o essai.o  -lm `pkg-config --cflags --libs gtk+-2.0`
*/
-----------------------------------------------------------
When I select an item, I get a segmentation fault.
I replaced gtk_combo_box_get_active_text with the following
that makes this problem disappear :
-----------------------------------------------------------
gchar *
my_gtk_combo_box_get_active_text (GtkComboBox *combo_box)
{
  GtkTreeIter iter;
  gchar *text = NULL;

  GtkTreeModel* model = gtk_combo_box_get_model(combo_box);

  if (gtk_combo_box_get_active_iter (combo_box, &iter))
    gtk_tree_model_get (model, &iter, 0, &text, -1);

  return text;
}
------------------------------------------------------------




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