SFML 和 GTK+ -GtkFileChooserDialog
我正在使用 SFML 编写一个应用程序,我想使用 GTK+ 创建文件选择器对话框。我有这个代码:
gtk_init(&argc, &argv);
GtkWidget *dialog;
dialog = gtk_file_chooser_dialog_new ("Open file...", NULL, GTK_FILE_CHOOSER_ACTION_OPEN, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, NULL);
gtk_dialog_run (GTK_DIALOG (dialog));
并且对话框正在显示,但它没有被破坏:(
I'm writing an app using SFML and I want to use GTK+ to create file chooser dialogs. I have this code:
gtk_init(&argc, &argv);
GtkWidget *dialog;
dialog = gtk_file_chooser_dialog_new ("Open file...", NULL, GTK_FILE_CHOOSER_ACTION_OPEN, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, NULL);
gtk_dialog_run (GTK_DIALOG (dialog));
And the dialog is showing, but it doesn't get destroyed :(
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在gtk_dialog_run文档中有一条注释
所以对话框不应该被自动销毁,程序员必须这样做。
EDIT:
另一个问题是您没有运行 GTK 主循环(
gtk_main()
或其变体),因此 GTK 无法处理销毁小部件所需的事件(GTK 的任何部分都没有在该时间内运行)事件存在)。此问题的解决方案位于使用gtk_idle_add( )
在gtk_main()
之后调用函数被称为。在此函数中,显示对话框,将结果提供给调用者,销毁对话框并调用 gtk_main_quit() 来终止 GTK 主循环。
但是,
gtk_idle_add()
在 GTK+2.6 中已被弃用,并且在 GTK+3.0 中不存在,因此应使用g_idle_add()
来代替。你的代码可能是这样的In the gtk_dialog_run documentation there is a note
So the dialog should not get destroyed automaticaly, the programmer must do it.
EDIT:
The another problem is that you are not running GTK main loop (
gtk_main()
or its variant) so the GTK can not deal with events necessary to destroy a widget (no part of GTK is running in the time the events are present). The sollution for this is in answer to another question usinggtk_idle_add()
to invoke function aftergtk_main()
is called. In this function the dialog is shown, the result is given to the caller, the dialog is destroyed and
gtk_main_quit()
is called to terminate GTK main loop.However,
gtk_idle_add()
is deprecated in GTK+2.6 and is not present in GTK+3.0, sog_idle_add()
should be used instead. Your code could be somethink like