//創建子執行緒
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()
{
讀取影像
}
uj5u.com熱心網友回復:
我覺得你子執行緒里面for回圈處理timer有問題,你可以試一下子執行緒里把for回圈先去掉直接start一次timer看能不能進slotuj5u.com熱心網友回復:
你可以看看你頭檔案那里是否把這個槽函式放到了slots:下面uj5u.com熱心網友回復:
for函式比較快,可能還沒等定時器定時到達就重啟了定時器,那樣就沒有進入槽函式了uj5u.com熱心網友回復:
沒有事件回圈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.
uj5u.com熱心網友回復:
為什么用for回圈開定時器呢?不用for回圈,直接timer_time->start(400);就可以打開定時器了呀
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/45602.html
標籤:Qt
下一篇:微信內支付的一點問題
