自定义事件处理程序中的 Qt QApplication::processEvents()

发布于 2024-10-10 01:02:15 字数 347 浏览 0 评论 0原文

是否可以在事件处理程序中调用 QApplication::processEvents() ,其中有一个很长的过程。我的程序因段错误而终止。我的代码是这样的:

void MyApplication::customEvent(QEvent* event)
{
  if(event->type() == UserEventCustom)
  {
    for(int i = 0; i < 99999; ++i)
    {
       QApplication::processEvents();
       doSomething();
    }

    event->accept();
  }
}

Is it possible to call QApplication::processEvents() inside the event handler, where there is a long process. My program terminates with Segfault. My code is something like this:

void MyApplication::customEvent(QEvent* event)
{
  if(event->type() == UserEventCustom)
  {
    for(int i = 0; i < 99999; ++i)
    {
       QApplication::processEvents();
       doSomething();
    }

    event->accept();
  }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

栖竹 2024-10-17 01:02:15

我怀疑 Ton van den Heuvel (来自评论)是正确的,您看到的是堆栈溢出。

然而,在我的公司,我们发现最好避免 processEvents()。我们的经验表明 processEvents() 会导致崩溃,我们尽量避免使用它。我会问自己是否可以重构代码以不调用 processEvents() 。例如,您可以生成一个线程来进行处理。

I suspect that Ton van den Heuvel (from comments) is correct that you are seeing a stack overflow.

However, at my company, we have found it best to avoid processEvents(). Our experience has shown processEvents() to cause crashes and we try to avoid its use. I would ask yourself whether you could refactor your code to do without the processEvents() call. For example, you might spawn a thread to do you processing.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文