G'Day,

I have the following code ( which works ) but during run time can potentially crash. It uses the qextserialport library.

Qt Code:
  1. recflag = true;
  2. rec = serialPort->bytesAvailable();
  3. while ( recflag )
  4. {
  5. serialPort->read( retdata, 60 );
  6. if ( retdata[39] == 0x4F && retdata[40] == 0x04B )
  7. {
  8. sendwin->label_2->setText("Switch "+swnum+" succeeded" );
  9. recflag = false;
  10. }
  11. else
  12. {
  13. errorlist << "\nswitch "+swnum+" failed";
  14. sendwin->label_2->setText( "Switch "+swnum+" FAILED" );
  15. errorflag = true;
  16. recflag = false;
  17. }
  18. }
To copy to clipboard, switch view to plain text mode 

If no data is seen on the serial port, the app just sits there until something comes in or I crash the app. My question is how can I implement a timer of, say 500ms, to break the loop. I have tried using a timer but they don't seem to trigger the slot.

Any suggestions would be greatly appreciated.

Thank, B1.