QtConcurrent子线程循环读取图片,不进入槽函数。本意是主窗口刷大图,开个线程定时刷局部小图

弄潮儿的乐园 2020-04-03 01:49:33

//创建子线程
int CGFPro::CreateThread()
{

int nReuslt = QtConcurrent::run(this, &CGFPro::StartReadImage);
return 0;
}

//假设循环十次,每次定时器结束触发读图
int CGFPro::StartReadImage()
{

QTimer *timer_time = new QTimer();
timer_time->setInterval(100);
connect(timer_time, &QTimer::timeout, this, &CGFPro::slot_TimeOut, Qt::DirectConnection);
//定时器刷新
for (int nIndex = 0; nIndex <10; nIndex++)
{
timer_time->start(400);
nIndex++;
}
return 0;
}

//读取指定文件夹下图片--不进入槽函数,无法读图,也不报错
void CGFPro::slot_TimeOut()
{
读取图像
}
...全文
620 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
开心大爆炸 2020-04-08
  • 打赏
  • 举报
回复
为什么用for循环开定时器呢?
不用for循环,直接timer_time->start(400);就可以打开定时器了呀
astro_lee 2020-04-07
  • 打赏
  • 举报
回复
没有事件循环timer事件怎么触发? 摘自QTimer文档: In multithreaded applications, you can use QTimer in any thread that has an event loop. To start an event loop from a non-GUI thread, use QThread::exec(). Qt uses the timer's thread affinity to determine which thread will emit the timeout() signal. Because of this, you must start and stop the timer in its thread; it is not possible to start a timer from another thread.
斜阳日落 2020-04-07
  • 打赏
  • 举报
回复
for函数比较快,可能还没等定时器定时到达就重启了定时器,那样就没有进入槽函数了
斜阳日落 2020-04-07
  • 打赏
  • 举报
回复
你可以看看你头文件那里是否把这个槽函数放到了slots:下面
抓紧猪尾巴 2020-04-05
  • 打赏
  • 举报
回复
我觉得你子线程里面for循环处理timer有问题,你可以试一下子线程里把for循环先去掉直接start一次timer看能不能进slot

16,216

社区成员

发帖
与我相关
我的任务
社区描述
Qt 是一个跨平台应用程序框架。通过使用 Qt,您可以一次性开发应用程序和用户界面,然后将其部署到多个桌面和嵌入式操作系统,而无需重复编写源代码。
社区管理员
  • Qt
  • 亭台六七座
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧