在单独的线程中运行pyQT GUI主应用程序 [英] Run pyQT GUI main app in seperate Thread
问题描述
我试图在我已经建立的应用程序中添加一个PyQt GUI控制台.但是PyQt GUI阻止了整个应用程序,使其无法完成其余工作.我尝试使用QThread,但这是从mainWindow类调用的.我想要在单独的线程中运行MainWindow应用程序.
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()
我的应用程序已经使用Python线程,所以我的问题是,以线程形式实现此过程的最佳方法是什么?
My application already uses Python Threads, So my question is, what is the best approach to achieve this process in a threaded form.
推荐答案
一种方法是
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.
这篇关于在单独的线程中运行pyQT GUI主应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!