Naumov Naumov - 1 month ago 7
C++ Question

gtkmm and FileChooserButton can't get file name

this is my code, I try get file_name after choose file with widget

FileChooserButton


Gtk::FileChooserButton *chooserButton = nullptr;
std::string idChooserButton = commonArray[b]["id"];
builder->get_widget(idChooserButton, chooserButton);
Php::call("var_dump",chooserButton);
if (strcmp(commonArray[b]["action"], "click") == 0) {
Php::Value callback = commonArray[b]["callback"];
chooserButton->signal_selection_changed().connect(
sigc::bind<Php::Value,Php::Value>(
sigc::mem_fun(*this, &ParserGtk::callbacks),
callback,
chooserButton->get_filename()
)
);
}


I call functino
get_filename
but
get_filename
return empty string "";

Answer

Signals and sigc::bind pass values computed at connection time. So when you do

chooserButton->get_filename()

This will return an empty string, the Gtk::FileChooserButton having not been displayed or used at that point.

You will need to call chooserButton->get_filename() in your call-back function to get the current value.

Comments