简体   繁体   English

集成到现有的pyqt GUI应用程序中

[英]Integrating twisted into existing pyqt GUI application

I am trying to add twisted to my already existing app. 我正在尝试将twisted添加到我现有的应用程序中。 According to this and other sources, I should import qt4reactor. 根据消息以及其他消息,我应该导入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'. 我收到了twisted.application.reactors.NoSuchReactor:“ pyqt4”。 I can download and install qt4reactor directly, but then I can't install it after instantiating QApplication? 我可以直接下载并安装qt4reactor,但是实例化QApplication之后不能安装它吗?

Also, since I am adding on twisted, the documentation states that I should use reactor.runReturn() instead of reactor.run(). 另外,由于我要添加扭曲的内容,因此文档指出我应该使用Reactor.runReturn()而不是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'. 当我尝试这个时,我得到AttributeError:'SelectReactor'对象没有属性'runReturn'。 Is this because I am unable to install qt4reactor after instantiating QApplication? 这是因为实例化QApplication之后无法安装qt4reactor吗?

Now qt4reactor is separate from Twisted and located here 现在,qt4reactor与Twisted分离,并位于此处

So you need to install it first, then try: 因此,您需要先安装它,然后尝试:

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

or 要么

from qtreactor import pyqt4reactor
pyqt4reactor.install()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM