buffer=socket - & gt; ReadAll ();
Anticollision (buffer, carArray);//data conversion
If (learnFlag)
{
The UI - & gt; TextEdit_recv - & gt; SetText (" start early warning ");
If (UI - & gt; LeftButton - & gt; IsChecked ()==true)
EarlyWarningLeft (carArray, border);//whether the data is not in conformity with the provisions of
The else
If (UI - & gt; RigthButton - & gt; IsChecked ()==true)
EarlyWarningRight (carArray, border);//whether the data is not in conformity with the provisions of
}
Void earlyWarningLeft (carData carArray [64], int border [64])
{
for(int i=0; i<64; I++)
If (border [I]Warming ();
}
Want warming () alarm only once every 5 seconds, but readAll () run normally, sleep () will lead to the blocking of the whole program,
CodePudding user response:
To create a cache, put the data you want to deposit the 5 seconds,Socket threads related operations at each other. Can not block the UI, this thread threw things to deal with the cache is finished,
Police made a separate thread to sleep for 5 seconds or QTimer interval 5 s trigger, execution: read buffer to use message then processing, processed to empty, (multithreaded remember locking)
CodePudding user response:
Use QTimer