QThreads and QSerialPort
-
Hello all,
I'm a Qt beginner. I have tried reading and writing data to Arduino using Serialport. It works fine.
Now, I want to implement the same using threads and I wanna know that is there any options available to embed Serialport functionalities in threads or any other suggestions would help.I tried searching resources which would help me in this topic, But I couldn't find any.
Thanks in advance! : )
-
Hi
Yes you can use QSerialPort in a thread but do you really need it ?
It's asynchronous already meaning it won't pause your app while reading.However, sometimes the processing of the incoming data takes up too much time
and hence this processing could be moved to a thread.However, if just for leaning here is one example
https://evileg.com/en/post/290/Note its using the blocking api of serialport. not the signal based.
Here they use the signals in a class called SerialWorker that runs in a thread
https://www.programmersought.com/article/93167931470/
sorry for all the ads. The code is fine though.
You can just grab the SerialWorker class and use.
Do note that from another thread, you are not not allowed to touch any widget in the main GUI.
So if you want to update anything ui->xxxxx it has to be done via signals and slot. not via pointers into
Mainwindow.