[Twisted-Python] integrating a Qt interface with twisted, qt5, python 2.x
hi, why does the code below print "testing..." but not "123" 5 seconds after the application started? import sys from PyQt5 import QtWidgets from untitled import Ui_MainWindow #from webchat import get_main_page class Main(QtWidgets.QMainWindow): def __init__(self): QtWidgets.QMainWindow.__init__(self) self.ui = Ui_MainWindow() self.ui.setupUi(self) self.setupSignals() def button_1_Clicked(self): self.ui.textbox_2.setText(self.ui.textbox_1.text()) def setupSignals(self): #self.ui.textbox_1.textChanged.connect(self.textbox_1_Changed) self.ui.button_1.clicked.connect(self.button_1_Clicked) if __name__ == '__main__': #app = QtWidgets.QApplication(sys.argv) app = QtWidgets.QApplication(sys.argv) # your code to init QtCore import qt5reactor qt5reactor.install() print "testing..." #get_main_page() window = Main() window.show() sys.exit(app.exec_()) def printMe(argument): print argument def lala(): reactor.callLater(5, printMe, '123') lala() reactor.run()
I believe your problem is this line:
sys.exit(app.exec_())
Two issues:
- It looks like app.exec_() blocks (e.g.
http://stackoverflow.com/questions/22289423/how-to-avoid-qt-app-exec-blockin...
)
- When it unblocks, the program sys.exit() terminates (
https://docs.python.org/2/library/sys.html#sys.exit)
Thus, your app never reaches any of the twisted code. If you're not
familiar with debugging tools that let you walk through the code, adding a
print line between each line of actual code would have made it obvious that
you never got past this line.
Clayton Daley
On Fri, Jun 17, 2016 at 11:26 AM, steven meier
hi,
why does the code below print "testing..." but not "123" 5 seconds after the application started?
import sys from PyQt5 import QtWidgets from untitled import Ui_MainWindow #from webchat import get_main_page
class Main(QtWidgets.QMainWindow):
def __init__(self): QtWidgets.QMainWindow.__init__(self) self.ui = Ui_MainWindow() self.ui.setupUi(self) self.setupSignals()
def button_1_Clicked(self): self.ui.textbox_2.setText(self.ui.textbox_1.text())
def setupSignals(self): #self.ui.textbox_1.textChanged.connect(self.textbox_1_Changed) self.ui.button_1.clicked.connect(self.button_1_Clicked)
if __name__ == '__main__': #app = QtWidgets.QApplication(sys.argv)
app = QtWidgets.QApplication(sys.argv) # your code to init QtCore import qt5reactor qt5reactor.install()
print "testing..."
#get_main_page() window = Main() window.show() sys.exit(app.exec_()) def printMe(argument): print argument
def lala(): reactor.callLater(5, printMe, '123')
lala() reactor.run()
_______________________________________________ Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
participants (2)
-
Clayton Daley
-
steven meier