问题描述
我正在使用QRunnable类从gui启动单独的线程(用于非阻塞功能)。该线程正在使用Matplotlib将某些图另存为pdf。但是它给出了一些警告
class Results(QRunnable):
def __init__(self):
super(Results,self).__init__()
def run(self):
plt.plot([1,2,3,4],[1,4])
plt.savefig('plot.pdf')
class MainWindow(QMainWindow):
def __init__(self,*args,**kwargs):
super(MainWindow,self).__init__(*args,**kwargs)
self.threadpool = QThreadPool()
layout = QVBoxLayout()
self.l = QLabel("Start")
b = QPushButton("DANGER!")
b.pressed.connect(self.oh_no)
layout.addWidget(self.l)
layout.addWidget(b)
w = QWidget()
w.setLayout(layout)
self.setCentralWidget(w)
self.show()
def oh_no(self):
worker = Results()
self.threadpool.start(worker)
app = QApplication([])
window = MainWindow()
app.exec_()
这些是警告:
QPixmap: It is not safe to use pixmaps outside the GUI thread
QPainter::begin: Paint device returned engine == 0,type: 2
QPainter::setRenderHint: Painter must be active to set rendering hints
QPainter::setBrush: Painter not active
QPainter::translate: Painter not active
QPainter::translate: Painter not active
QPainter::setBrush: Painter not active
QPainter::setPen: Painter not active
QPainter::translate: Painter not active
QPainter::setBrush: Painter not active
QPainter::setPen: Painter not active
QPixmap: It is not safe to use pixmaps outside the GUI thread
QObject: Cannot create children for a parent that is in a different thread.
(Parent is Oxygen::WidgetStateEngine(0x282cdc0),parent's thread is QThread(0x141baf0),current thread is QThread(0x2a87e60)
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)