开发者

Qt QApplication::processEvents() in custom event handler

开发者 https://www.devze.com 2023-02-02 06:12 出处:网络
Is it possible to call QApplication::processEvents() inside the event han开发者_运维问答dler, where there is a long process. My program terminates with Segfault. My code is something like this:

Is it possible to call QApplication::processEvents() inside the event han开发者_运维问答dler, 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();
  }
}


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消