我在程序后台运行超时功能,并尝试从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;
}
}

现在,当用户单击退出按钮时,我要发出删除事件信号。问题:如何像C g_signal_emit或g_signal_emit_by_name一样在gtkmmm中发射信号?
void AlarmUI::on_button_quit () {
// m_deleteSlot.emit (); ???
}

更新1:
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;

最佳答案

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

09-04 09:03