camerausb camerausb - 1 year ago 62
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

(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

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

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 Source

Now qt4reactor is separate from Twisted and located here

So you need to install it first, then try:

from twisted.application import reactors


from qtreactor import pyqt4reactor