gtkmm 和 FileChooserButton 无法获取文件名

gtkmm and FileChooserButton can't get file name

本文关键字:获取 文件名 FileChooserButton gtkmm      更新时间:2023-10-16

这是我的代码,我尝试得到file_name后选择文件与小部件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()
            )
    );
}

我调用函数get_filename,但get_filename返回空字符串";

信号和sigc::bind传递连接时计算的值。所以当你输入

chooserButton->get_filename()

这将返回一个空字符串,此时Gtk::FileChooserButton还没有被显示或使用。

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