Hi lago,

Thnx a lot for the help. Its working fine now. I think i got my
concepts clear now.

cheers
Sandy

On Mon, 24 Jan 2005 13:49:48 +0100, Iago Rubio <[EMAIL PROTECTED]> wrote:
> On Mon, 2005-01-24 at 08:10, Sandy wrote:
> > Hi,
> >
> > I am trying to build an application which encrypts/ decrypts files or
> > directories as required.
> > I am using Fedora core 3 with kernel version 2.6.9-1.667. I am
> > developing the GUI using Glade 2.6.0.
> >
> > I am trying to select a file name using the gtk_file_selection_new
> > method and display the selected file name in a text box. On clicking
> > the add file button I am getting a error message
> >
> > "Gtk-CRITICAL **: file gtkentry.c: line 3717 (gtk_entry_set_text):
> > assertion `text != NULL' failed".
> >
> > the file name is not being displayed on the text box at that instant.
> > If the add file button is clicked again, the text box is being
> > populated with the previous selsected filename.
> 
> > The code is like this:
> >
> > GtkWidget *file_selector;
> > const gchar *selected_filename;
> >
> > void
> > store_filename(GtkFileSelection *selector, gpointer user_data)
> > {
> >    selected_filename = gtk_file_selection_get_filename
> > (GTK_FILE_SELECTION(file_selector));
> > }
> >
> > void
> > on_button3_clicked                     (GtkButton       *button,
> >                                         gpointer         user_data)
> > {
> >   GtkWidget * entry = lookup_widget(GTK_WIDGET(button), "entry1");
> >
> >  /* Create the selector */
> >    file_selector = gtk_file_selection_new("Please select a file for 
> > editing.");
> >    gtk_entry_set_text(GTK_ENTRY(entry),selected_filename);
> 
> Here you first call to set the text ....
> 
> >    gtk_signal_connect (GTK_OBJECT
> > (GTK_FILE_SELECTION(file_selector)->ok_button),
> >                            "clicked", GTK_SIGNAL_FUNC (store_filename), 
> > NULL);
> 
> ... then you connect the callback, so the callback will never be called 
> before to update the local variable, but after that.
> 
> >    /* Ensure that the dialog box is destroyed when the user clicks a 
> > button. */
> >
> >    gtk_signal_connect_object (GTK_OBJECT
> > GTK_FILE_SELECTION(file_selector)->ok_button),
> >                                           "clicked", GTK_SIGNAL_FUNC
> > (gtk_widget_destroy),
> >                                           (gpointer) file_selector);
> >
> >    gtk_signal_connect_object (GTK_OBJECT
> > (GTK_FILE_SELECTION(file_selector)->cancel_button),
> >                                           "clicked", GTK_SIGNAL_FUNC
> > (gtk_widget_destroy),
> >                                           (gpointer) file_selector);
> >
> >    /* Display that dialog */
> >    gtk_widget_show (file_selector);
> > }
> 
> You should get rid of local variables:
> 
> void
> on_button3_clicked                     (GtkButton       *button,
>                                         gpointer         user_data)
> {
>   GtkWidget * entry = lookup_widget(GTK_WIDGET(button), "entry1");
>   gint response;
>   G_CONST_RETURN gchar* filename;
> 
>   /* Create the selector */
>    file_selector = gtk_file_selection_new("Please select a file for 
> editing.");
>    response = gtk_dialog_run(GTK_DIALOG(file_selector));
>    if( response == GTK_RESPONSE_OK ){
>         filename = gtk_file_selection_get_filename(
>                 GTK_FILE_SELECTION(file_selector));
>         if( filename )
>                 gtk_entry_set_text(GTK_ENTRY(entry),filename);
>         else
>                 // no filename in file selector, so err
>    }
>    gtk_widget_destroy( file_selector );
> }
> 
> > Please guide me in resolving this error.
> 
> The long explanation is signals are called on the main loop, so the
> local variable may not be updated when the signal arise.
> 
> Even worst you're calling gtk_entry_set_text before to connect the
> signal so it will never be updated as you want.
> 
> Regards.
> --
> Iago Rubio
> _______________________________________________
> gtk-app-devel-list mailing list
> gtk-app-devel-list@gnome.org
> http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
> 


-- 
Cheers
Sandy
_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Reply via email to