销毁gtkmm消息对话框
destroy gtkmm message dialog?
我使用的是gtkmm 3.0.1,在用户单击按钮后创建Gtk::MessageDialog
对象以销毁对话框时,我看不到任何选项。我发现销毁消息对话框的唯一方法是在辅助函数中调用它,但我觉得这是可以避免的。文档中没有提到销毁它的方法,只提到由用户销毁它
这是我的代码:
#include <gtkmm.h>
#include <iostream>
using namespace std;
int main(int argc, char *argv[]) {
Gtk::Main kit(argc, argv);
Gtk::Window client;
Gtk::MessageDialog dialog("Info", false, Gtk::MESSAGE_QUESTION, Gtk::BUTTONS_YES_NO);
dialog.set_secondary_text( "Dialog");
dialog.set_default_response(Gtk::RESPONSE_YES);
dialog.run();
cout << "dialog is still open, needs to be destroyed at this point." << endl;
Gtk::Main::run(client);
return EXIT_SUCCESS;
}
问题是您已经在int main
中的堆栈上创建了Gtk::MessageDialog
。由于该函数在程序完成之前不会退出,因此MessageDialog
将挂起。
少数选项:
1.)使用后隐藏对话框,当int main退出时,它将被销毁。
2.)新建然后删除。
Gtk::MessageDialog* dialog = new Gtk::MessageDialog("Info", false, Gtk::MESSAGE_QUESTION, Gtk::BUTTONS_YES_NO);
dialog->set_secondary_text( "Dialog");
dialog->set_default_response(Gtk::RESPONSE_YES);
dialog->run();
delete dialog;
3.)在它自己的函数或块中创建它,这样当该作用域退出时,它就会被销毁。
void showDialog() {
Gtk::MessageDialog dialog("Info", false, Gtk::MESSAGE_QUESTION, Gtk::BUTTONS_YES_NO);
dialog.set_secondary_text( "Dialog");
dialog.set_default_response(Gtk::RESPONSE_YES);
dialog.run();
}
int main(int argc, char *argv[]) {
etc...
showDialog();
Gtk::Main::run(client);
etc...
}
相关文章:
- 如何在Qbutton的帮助下更改Q对话框的宽度
- 当对话框被接受时,如何用参数调用槽
- WinAPI 在单击第一个对话框上的按钮控件并销毁第一个对话框后创建第二个对话框
- 如何多次询问来自QML对话框的输入?
- winrt消息对话框未显示
- QInput对话框和Q消息框
- 主对话框在命令消息处理程序返回之前销毁
- 如何在窗口提示对话框(即错误消息)时获取通知
- 对话框消息是否发送到自定义消息循环
- 在 MFC 对话框和自己的线程上的 OpenGL 控件之间传递消息
- 如何在 Win32 API 的对话框中显示自定义消息
- 销毁gtkmm消息对话框
- 接收MFC对话框的PostMessage消息
- 在c++中对来自其他正在运行的线程的消息对话框进行建模
- 从主框架到Dockpane对话框的消息通知
- 在对话框消息过程中获取应用对象指针
- 带有SDL的对话框/消息框
- 将消息发布到模型对话框
- MFC 对话框后不显示消息框
- 对话框窗口中的MFC消息循环