My hint is - don't mix the logic and implementation. Application "logic" requires that there should be an object that handles communication with the serial port, but the fact that it should/shouldn't use threads is specific to implementation (another "logic" requirement could be that it shouldn't block the ui, but that can be achieved without threads). So my suggestion is to wrap the serial communication mechanism into a class interface, and use some threading mechanism as another layer - through QThread, thread pools, QtConcurrent or whatever suits your needs.
So don't do this:
{
...
}
// what does it even mean that "Every SerialIO object is a kind of Thread object" ?
class SerialIO : public QThread
{
...
}
// what does it even mean that "Every SerialIO object is a kind of Thread object" ?
To copy to clipboard, switch view to plain text mode
but rather:
{
...
}
...
SerialIO * io = new SerialIO(...);
io->moveToThread(thread);
class SerialIO : public QObject
{
...
}
...
SerialIO * io = new SerialIO(...);
QThread * thread = new QThread(...);
io->moveToThread(thread);
To copy to clipboard, switch view to plain text mode
this way you have a possibility to enable / disable threading support for the serial io without changing the core communication code.
Bookmarks