什么是gtkmm的g_signal_emit或g_signal_emit_by_name版本?

时间:2015-02-28 16:11:42

标签: c++ signals gtk3 gtkmm

我在程序后台运行超时功能,并且我试图从Gtk :: Button发出删除事件信号,这是我构造函数中的代码片段:

// Glib::SignalProxy1<bool,GdkEventAny*> m_deleteSlot;
// m_deleteSlot =
signal_delete_event().connect (sigc::mem_fun (*this, &AlarmUI::my_delete_event));
m_timeout_connection = Glib::signal_timeout().connect_seconds(sigc::mem_fun(*this, &AlarmUI::cb_my_tick), 1);`

现在,方法:

bool AlarmUI::my_delete_event (GdkEventAny *event) {
if (m_timeout_connection.connected ()) {
    // show messagebox here
    return true;
} else {
    // bye bye
    return false;
}
}

现在,当用户点击退出按钮时,我想发出删除事件信号。问题:如何在gtkmmm中发出信号,如C g_signal_emit或g_signal_emit_by_name?

void AlarmUI::on_button_quit () {
// m_deleteSlot.emit (); ???
}

UPDATE1:

Glib::RefPtr<Gtk::Application> app = Gtk::Application::create (argc, argv, PACKAGE);
Glib::RefPtr<Gtk::Builder> refBuilder = Gtk::Builder::create ();
try { 
    refBuilder->add_from_file (UI_PATH);
}
catch (const Glib::FileError& ex) {
    std::cout << "FileError: " << ex.what() << std::endl;
    return 1;
}
catch (const Gtk::BuilderError& ex) {
    std::cout << "BuilderError: " << ex.what() << std::endl;
    return 1;
}
catch(const Glib::MarkupError& ex)
{
    std::cout << "MarkupError: " << ex.what() << std::endl;
    return 1;
}
AlarmUI *ui = 0;
refBuilder->get_widget_derived ("window1", ui);
if (ui) {
    ui->show_all ();
    app->run (); // The window doesn't show
}
delete ui;

1 个答案:

答案 0 :(得分:0)

从小部件外部发出小部件信号通常不明智。这干扰了小部件实现的内部。如果你想隐藏窗口你可以调用window.hide(),如果你想要销毁它,你可以删除它。或者您可以通过发出删除事件信号直接执行您想要间接触发的任何其他内容。