Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Take a look at <a href="http://qextserialport.sourceforge.net/" rel="nofollow noreferrer">QextSerialPort</a>:</p> <blockquote> <p>QextSerialPort is a cross-platform serial port class. This class encapsulates a serial port on both POSIX and Windows systems.</p> </blockquote> <p><a href="http://qextserialport.sourceforge.net/qextserialport-1.1.x/" rel="nofollow noreferrer">QextSerialPort</a> inherits from <a href="http://doc.qtsoftware.com/4.5/qiodevice.html" rel="nofollow noreferrer">QIODevice</a> and makes serial port communications integrate more smoothly with the rest of the Qt API.</p> <p>Also, you could use a message passing scheme for communications between the I/O and GUI threads instead of shared memory. This is often much less error prone. You can use the <a href="http://doc.trolltech.com/4.5/qcoreapplication.html#postEvent" rel="nofollow noreferrer">QApplication::postEvent</a> function to send custom QEvent messages to a QObject to be processed in the GUI thread with the <a href="http://doc.trolltech.com/4.5/qobject.html#customEvent" rel="nofollow noreferrer">QObject::customeEvent</a> handler. It will take care of synchronization for you and alleviate your deadlock problems..</p> <p>Here is a quick and dirty example:</p> <pre><code>class IODataEvent : public QEvent { public: IODataEvent() : QEvent(QEvent::User) {} // put all of your data here }; class IOThread : public QThread { public: IOThread(QObject * parent) : QThread(parent) {} void run() { for (;;) { // do blocking I/O and protocol parsing IODataEvent *event = new IODataEvent; // put all of your data for the GUI into the event qApp-&gt;postEvent(parent(), event); // QApplication will take ownership of the event } } }; class GUIObject : public QObject { public: GUIObject() : QObject(), thread(new IOThread(this)) { thread-&gt;start() } protected: void customEvent(QEvent *event) { if (QEvent::User == event-&gt;type) { IODataEvent *data = (IODataEvent *) event; // get data and update GUI here event-&gt;accept(); } else { event-&gt;ignore(); } // the event loop will release the IODataEvent memory automatically } private: IOThread *thread; }; </code></pre> <p>Also, Qt 4 <a href="http://doc.trolltech.com/4.5/threads.html#signals-and-slots-across-threads" rel="nofollow noreferrer">supports queing signals and slots across threads</a>.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload