My program continuously reads from serial port. Firstly, I used QTimer and set the interval to 300 mlscnd, this makes UI interaction very slow. I though of converting QTimer to QThread, as QTimer runs in the UI Thread, so, I added QThread class and used msleep() inside the while() loop to control the trigger.
Unfortunately, the program is still slow, I can clearly understand this when I enter digits in the UI. My last guess of where the speed reduction might have come from is emit, as you see below:
void PlcTimer::run(){
while(1)
{
qDebug() << "updateJack()";
const char str[]={UPDATE_m};
#if DEBUG
qDebug() << built.toHex();
#endif
emit m_sendToRS((char* )str, 3);
this->msleep(500);
//sleep(300);
}
}
void PlcTimer::run(){
while(1)
{
qDebug() << "updateJack()";
const char str[]={UPDATE_m};
#if DEBUG
QByteArray built(str, 3);
qDebug() << built.toHex();
#endif
emit m_sendToRS((char* )str, 3);
this->msleep(500);
//sleep(300);
}
}
To copy to clipboard, switch view to plain text mode
emit is a UI object, so whatever it is I am suspicious of its interconnection over the UI. do you have any idea how I can resolve the low speed?
Bookmarks