[Solved] Serial - Thread - GUI - Webkit ... need suggestion
I have an application that has a GUI, mainly consisting of a WebView, and that is getting commands by serial port. I currently have all in a single thread.
I read a lot about using a separate thread to not have the serial port communication blocking the GUI. I have exactly the opposite issue. The GUI - namely the Webview is sometimes blocking and the serial port does not pick up incoming data fast enough ending in the ack sent too late.
What is the correct approach here?
Do I move all of the serial port functions (onComReadyRead(), protocolChecker(), SerialWrite() ... and everything related) to a separate thread and communicate to the rest of the application by slot/signals?
I am using QextSerialPort on Qt 4.6.3 on eLinux with directFB.
Thanks for any hint to step in the right direction.
This post is deleted!
I solved this.
I moved everything related to the serial port into a separate class SerialWorker and moved it to a separate thread.
QThread* serialthread = new QThread; SerialWorker* serialworker = new SerialWorker(); serialworker->moveToThread(serialthread); connect(serialthread, SIGNAL(started()), serialworker, SLOT(InitSerialPort())); serialthread->start(); connect(serialworker, SIGNAL(NewProto(QByteArray)), this, SLOT(ProtocolInterpreter(QByteArray))); connect(this, SIGNAL(SendRS(QByteArray)) , serialworker, SLOT(writeData(QByteArray)));
This works as supposed. Serial port is now more or less very responsive.
WebKit is still blocking the GUI thread sometimes but thats not as much an issue as the serial port not responding.