Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
353 views
in Technique[技术] by (71.8m points)

python - Run pyQT GUI main app in seperate Thread

I am trying to add a PyQt GUI console in my already established application. But the PyQt GUI blocks the whole application making it unable to do rest of the work. I tried using QThread, but that is called from the mainWindow class. What I want is to run the MainWindow app in separate thread.

def main()
      app = QtGui.QApplication(sys.argv)
      ex = Start_GUI()
      app.exec_()  #<---------- code blocks over here !

      #After running the GUI, continue the rest of the application task
      doThis = do_Thread("doThis")
      doThis.start()
      doThat = do_Thread("doThat")
      doThat.start()

My application already uses Python Threads, So my question is, what is the best approach to achieve this process in a threaded form.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

One way of doing this is

import threading

def main()
      app = QtGui.QApplication(sys.argv)
      ex = Start_GUI()
      app.exec_()  #<---------- code blocks over here !

#After running the GUI, continue the rest of the application task

t = threading.Thread(target=main)
t.daemon = True
t.start()

doThis = do_Thread("doThis")
doThis.start()
doThat = do_Thread("doThat")
doThat.start()

this will thread your main application to begin with, and let you carry on with all the other stuff you want to do after in the code below.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...