对于利用QMdiArea构建的主窗口进程,如果主进程中的数据改变,则在对应的子窗口QMdiSubWindow中显示对应的数据。这里通过主进程对Queue监测,如果Queue非空,则从队列中put该值,并将该值以信号量的方式发送给对应的线程,并在线程中找到子窗口对应的对象,对对象中相应的控件进行修改。
main.py
from ui_demo import MainWindow
from PyQt5.QtWidgets import QApplication
from multiprocessing import Process,Queue
import random
import time
import sys
def process1(queue):
while 1:
test=random.randint(0,1)
queue.put([test,[random.randint(0,100),random.randint(0,100)]])
time.sleep(1)
def process2(queue1,queue2):
app=QApplication(sys.argv)
demo=MainWindow(queue1,queue2)
demo.show()
sys.exit(app.exec_())
def process3(queue):
while 1:
queue.put([random.randint(0,1),[random.randint(0,1),random.randint(0,1),random.randint(0,1)]])
time.sleep(1)
if __name__ == '__main__':
q1=Queue(maxsize=100)
q2 = Queue(maxsize=100)