PyQt5 QImage" init()从未调用"多处理期间的问题

时间:2017-09-02 09:00:17

标签: python pyqt multiprocessing pyqt5 qimage

当一个QImage对象在另一个进程中创建并传递回主进程时,我总是得到 " RuntimeError:QImage类型的超类 init ()从未被调用过"如果我尝试访问QImage方法。

版本:PyQt5.9 / Python3

请提前感谢简化代码!

import multiprocessing
from PyQt5.QtGui import QImage

class Process(multiprocessing.Process):
    def __init__(self,resultQ):
        multiprocessing.Process.__init__(self)
        self.resultQ = resultQ
        self.test = QImage(100,100,4) #create a QImage object

    def run(self):
        self.resultQ.put(self.test)

if __name__ == "__main__":
    jobs = []
    resultQ = multiprocessing.Queue()

    for i in range(5):
        x = Process(resultQ)
        jobs.append(x)

    for each in jobs:
        each.start()

    for each in jobs:
        each.join()

    result = []
    for each in jobs:
        result.append(resultQ.get())

    print(result) #Result shows QImage objects are in the list

    t = result[0].pixel(1,10) #Error here while accessing a method of QImage

0 个答案:

没有答案