gtkmm 和 FileChooserButton 无法获取文件名

gtkmm and FileChooserButton can't get file name

这是我的代码,我在使用小部件 FileChooserButton

选择文件后尝试获取 file_name
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()
            )
    );
}

我调用 functino get_filename 但是 get_filename return 空字符串 "";

信号和 sigc::bind 传递在连接时计算的值。所以当你这样做时

chooserButton->get_filename()

这将 return 一个空字符串,此时 Gtk::FileChooserButton 尚未显示或使用。

您需要在回调函数中调用 chooserButton->get_filename() 来获取当前值。