今天遇到这个问题
程序是次线程处理完数据后,发射一个信号给主线程,显示更新图片,然后提示QPixmap: It is not safe to use pixmaps outside the GUI thread
提示这个错误的时候两个线程之间的信号槽连接属性是Qt::DirectConnection,会提示不是在GUI线程里
后面属性改为默认的,不写,就不会出现这个问题了。
关键还是看连接属性的具体说明:
Qt::AutoConnection 0 (default) If the signal is emitted from a different thread than the receiving object, the signal is queued, behaving as Qt::QueuedConnection. Otherwise, the slot is invoked directly, behaving as Qt::DirectConnection. The type of connection is determined when the signal is emitted.
Qt::DirectConnection 1 The slot is invoked immediately, when the signal is emitted.
Qt::QueuedConnection 2 The slot is invoked when control returns to the event loop of the receiver's thread. The slot is executed in the receiver's thread.