I’m working on a Glade3 interface using the C language.
So far, I have two places where a user picks where to save a file. I have a GtkFileChooserDialog that opens when you click a browse button. When you click save on that dialog, it fills a GtkEntry that was next to the Browse button.
It works the first time you select a file, but the second time, gtk_file_chooser_get_filename() returns nothing, even if you enter something in the dialog.
Here is a simplified version of the source code, that still has the problem: http://paste.ubuntu.com/1032567/ and the Glade3 interface file to go with it: http://paste.ubuntu.com/1032572/
I have two places in my UI with a setup like this. Happens on both of them. I have two different callback functions–one is an older attempt to do it right and another is my latest attempt. Neither one works, though the newer avoids segfaulting because it checks to see if what is returned is null.
The newer callback is on_button5_clicked() and the older on_button3_clicked.
I’ve looked at the reference, and I didn’t see anything about why it would return a null pointer even though you have a filename choosen.
Any help would be greatly appreciated. (I feel like I’m at the headbanging stage).
EDIT:
So, I had a few more ideas of things to try. First, I tried making my own windows with a FileChooser widget, instead of having a dialog. I did this to make sure that the dialog was not having trouble with not being run with a gtk_Dialog_Run call. I also tried repeating the code that gets and checks to see if the pointer to the filename string is not null. When it is run for the second time in the same callback call, it returns a non-null string pointer. I also did this to make sure that it wasn’t something to do with the fact that the window the dialog is launched (actually, gtk_widget_show()ED) from is itself a dialog.
I tried my theory that I have to set the buttons in the dialog to have gtk.RESPONSE_OK or gtk_RESPONSE_CANCEL responses. That didn’t seem to have any effect.
It seems that calling
gtk_file_chooser_get_filename()will return null the second time hidden and shown the widget, unless you callgtk_file_chooser_set_filename().I do not see anything in the documentation about this, but most of the time, it would make sense to set the file name before showing it because whatever you were getting the filename for could have been changed, and so it makes sense to update the file chooser anyways.