gtk_events_pending()返回FALSE的事件仍悬而未决 [英] gtk_events_pending() returns FALSE with events still pending

查看:252
本文介绍了gtk_events_pending()返回FALSE的事件仍悬而未决的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的工作,有一个开始和停止按钮的应用程序。这些按钮阻止用户界面,并且由于种种原因,我不能生成一个线程。

我已经表现出工作画面时,这些按钮是pressed,使用:

 而(gtk_events_pending())gtk_main_iteration();

这确保了工作画面开始之前加载

/停止操作开始。

我最近升级到了GTK + 3.8.6,它似乎是 gtk_events_pending()现在是打破。现在,有时窗口显示,但在窗口中的图像是不存在。有时窗口甚至不显示。

在有问题的功能如下:

  gtk_widget_show(working_screen);
而(gtk_events_pending())gtk_main_iteration();long_running_blocking_function();

如果我做这样的事情:

  INT busy_wait = 0;
gtk_widget_show(working_screen);
而(gtk_events_pending()|| busy_wait小于5)
{
    gtk_main_iteration();
    如果(gtk_events_pending()!)++ busy_wait;
}long_running_blocking_function();

...它工作正常。但是,我知道这只是一个时间问题,直到busy_wait需要比较长,所以我想找到一个更好的答案。有没有人遇到过这个问题?有谁对我怎么可能解决它的任何想法?


解决方案

尝试 g_main_context_pending(NULL) g_main_context_iteration(NULL,FALSE)而不是 gtk_events_pending(),后来是去precated。


这可能是在踢一个时间问题(它oculd是你的循环踢任何事件注册之前,主循环,从而立即退出) - 但是这仅仅是野生猜测,由于缺乏code的


断点条件也是错误的,你不希望因为所有事件都在一个特定的时间点处理,以尽快退出,你要继续下去,直到长期-OPS完成。
这意味着你需要,当你操作完成的信号,检查标志您目前使用的循环,并使用阻断 * _迭代(...)

I'm working on an application that has a start and stop button. These buttons block the UI, and for various reasons, I can't spawn a thread.

I've been showing a working screen when these buttons are pressed, using:

while (gtk_events_pending()) gtk_main_iteration();

which ensures that the working screen is loaded before the start/stop operations begin.

I've recently upgraded to GTK+ 3.8.6, and it seems that gtk_events_pending() is now broken. Now, sometimes the window shows, but the image in the window isn't there. Sometimes the window doesn't even show.

The function in question looks like:

gtk_widget_show(working_screen);
while (gtk_events_pending()) gtk_main_iteration();

long_running_blocking_function();

If I do something like:

int busy_wait = 0;
gtk_widget_show(working_screen);
while (gtk_events_pending() || busy_wait < 5) 
{
    gtk_main_iteration();
    if (!gtk_events_pending()) ++busy_wait;
}

long_running_blocking_function();

...it works fine. However, I know it's only a matter of time until the busy_wait needs to be longer so I'd like to find a better answer. Has anybody experienced this issue? Does anybody have any ideas about how I might work around it?

解决方案

Try g_main_context_pending(NULL) and g_main_context_iteration(NULL,FALSE) instead of gtk_events_pending(), the later is deprecated.


It could be a timing issue that kicks in (it oculd be that your loop kicks in before any events are registered to the mainloop, and thus instantly exits) - but this is just wild guessing due to lack of code.


The break condition is also wrong, you do not want to exit as soon as all events are processed at a specific point of time, you want to continue until long-run-ops are done. That means you need to signal when your operation is done, check that flag in the loop you currently use and use blocking mode of the *_iteration(...)

这篇关于gtk_events_pending()返回FALSE的事件仍悬而未决的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆