camerausb camerausb - 3 months ago 14
Python Question

Integrating twisted into existing pyqt GUI application

I am trying to add twisted to my already existing app. According to this and other sources, I should import qt4reactor. When I try:

app = QApplication(sys.argv)
from twisted.application import reactors
reactors.installReactor('pyqt4')


(I also tried:)

from twisted.internet import qt4reactor


I get twisted.application.reactors.NoSuchReactor: 'pyqt4'. I can download and install qt4reactor directly, but then I can't install it after instantiating QApplication?

Also, since I am adding on twisted, the documentation states that I should use reactor.runReturn() instead of reactor.run().

from twisted.internet import reactor, protocol
reactor.listenTCP(8001, tcpFactory())
reactor.runReturn()


When I try this, I get AttributeError: 'SelectReactor' object has no attribute 'runReturn'. Is this because I am unable to install qt4reactor after instantiating QApplication?

Answer

Now qt4reactor is separate from Twisted and located here

So you need to install it first, then try:

from twisted.application import reactors
reactors.installReactor('pyqt4')

or

from qtreactor import pyqt4reactor
pyqt4reactor.install()
Comments