1、官方解释文档:
Blocking Master shows how to create an application for a serial interface using the synchronous API of in a worker thread.
阻塞主程序显示了如何使用QSerialPort的同步API在同个工作线程中为串行接口创建应用程序。
supports two programming alternatives:
QSerialPort支持两种编程方法:
- The asynchronous (non-blocking) alternative. Operations are scheduled and performed when the control returns to the Qt event loop. The class emits a signal when the operation is finished. For example, the method returns immediately. When the data is sent to the serial port, the class emits the signal.
- The synchronous (blocking) alternative. In headless and multithreaded applications, the wait method can be called (in this case,) to suspend the calling thread until the operation has completed.
- 异步(不阻塞)二者选择一种。当控制返回到Qt事件循环时,调度并执行操作。QSerialPort类在操作完成时发出一个信号。例如,write()方法立即返回。当数据被发送到串行端口时,QSerialPort类会发出bytes笔试()信号。
- 同步(阻塞)的选择。在无头的和多线程的应用程序中,可以调用wait方法(在本例中,waitForReadyRead())暂停呼叫线程,直到操作完成。