gtkmm和FileChooserButton无法获取文件名

时间:2016-10-20 21:20:56

标签: c++ gtk3 gtkmm3

这是我的代码,我在选择带有小部件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返回空字符串“”;

1 个答案:

答案 0 :(得分:1)

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

chooserButton->get_filename()

这将返回一个空字符串,Gtk::FileChooserButton尚未在该点显示或使用。

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