Discussion:
[Twisted-Python] integrating a Qt interface with twisted, qt5, python 2.x
steven meier
2016-06-17 16:26:19 UTC
Permalink
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()
Clayton Daley
2016-06-19 15:34:30 UTC
Permalink
Post by steven meier
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-blocking-main-thread
)
- 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
Post by 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
QtWidgets.QMainWindow.__init__(self)
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
self.setupSignals()
self.ui.textbox_2.setText(self.ui.textbox_1.text())
#self.ui.textbox_1.textChanged.connect(self.textbox_1_Changed)
self.ui.button_1.clicked.connect(self.button_1_Clicked)
#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_())
print argument
reactor.callLater(5, printMe, '123')
lala()
reactor.run()
_______________________________________________
Twisted-Python mailing list
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
Loading...