Delay between characters write to serial port
-
Hi,
I want to send printable ascii characters from 32 to 126 (converted to string) to the serial port with a delay between each character. when start button is pressed the SendHandle () function is called. I want to send the ascii characters continuously with delay between each character. I have written a code as below but it hangs when i click the start button. Please help me in this regard.
void Widget::SendHandle ()
{
if(start==1)
{
for(i=32;i<=126;i++)
{QString str1= QChar(i); asc =str1.toUtf8(); Sleeper::msleep(delay); serial->write(asc); //writing data to serial port ui->display->moveCursor (QTextCursor::End); ui->display->insertPlainText (asc); ui->display->moveCursor (QTextCursor::End); ui->bitslcd->display(nchar); nchar++; }
}
} -
if you sleep in the GUI code
complete event engine is not called
so the GUI freezes
you can implement code by using signals & slotsor
you can call event engine using
QCoreApplication::processEvents
to process the events