//create the child thread
Int CGFPro: : CreateThread ()
{
Int nReuslt=QtConcurrent: : run (this, & amp; CGFPro: : StartReadImage);
return 0;
}
//assume that cycle, ten times each end of the timer trigger map reading
Int CGFPro: : StartReadImage ()
{
QTimer * timer_time=new QTimer ();
Timer_time - & gt; SetInterval (100);
The connect (timer_time, & amp; QTimer: : timeout, this, & amp; CGFPro: : slot_TimeOut , Qt: : DirectConnection);
//timer refresh
For (int nIndex=0; NIndex & lt; 10; NIndex++)
{
Timer_time - & gt; Start (400);
NIndex++;
}
return 0;
}
//read specified folder pictures - not into the groove function, cannot read, nor an error
Void CGFPro: : slot_TimeOut ()
{
Read image
}
CodePudding user response:
I think you the child thread inside the for loop handle the timer has a problem, you can try remove the first for loop in the thread can start a timer to see directly into the slotCodePudding user response:
You can see if a header file where you put this slot function in the slots: belowCodePudding user response:
For function is faster, may arrive before the timer timing on the resumption of the timer, so there is no function into the grooveCodePudding user response:
How do not cycle timer events trigger?From QTimer document:
In multithreaded applications, you can use QTimer In any thread that has an event loop. The event To start 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.
CodePudding user response:
Why use open timer for loop?Don't use a for loop, direct timer_time - & gt; Start (400); Can open the timer