gpt4 book ai didi

c++ - 从 for 循环开始线程会阻塞 UI

转载 作者:太空宇宙 更新时间:2023-11-04 14:55:59 25 4
gpt4 key购买 nike

我正在压缩视频,将来我想一次压缩多个帧。我有一个线程,我调用它来处理每个帧 - 这就是为什么我的 UI 类中有 for 循环。问题是 UI 被阻止了。为什么?这是因为我从 for 循环调用线程吗?

导致 UI 阻塞的代码 (Dialog.cpp):

for(int i=0; i<nFrames; i++)
{
//grab next frame from video source

myThread.setFrame(newFrame);
myThread.start();
myThread.wait();
result.append(myThread.GetResult());
}

最佳答案

您正在调用 wait,为什么您期望 wait 不会阻塞 ui?

来自 Qt 文档:

Blocks the thread until either of these conditions is met:

The thread associated with this QThread object has finished execution (i.e. when it returns from run()). This function will return true if the thread has finished. It also returns true if the thread has not been started yet. time milliseconds has elapsed. If time is ULONG_MAX (the default), then the wait will never timeout (the thread must return from run()). This function will return false if the wait timed out.

关于c++ - 从 for 循环开始线程会阻塞 UI,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14159755/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com