[PyQt] Help! I can't get my program to exit (using qt4reactor)

inhahe inhahe at gmail.com
Fri May 22 23:19:00 BST 2015


When I close the one window this program creates, the program doesn't
finish. How do I make it finish and return me to cmd.exe?
I tried calling exit() in closeEvent(), but that just makes the program
stop responding.

Here's my code.
And here's a pastebin link to the same code: http://pastebin.com/hWJQ3S86

import os, sys, time
import Queue
from PyQt4.QtCore import *
from PyQt4.QtGui import *

import qt4reactor
qt4reactor.install()


#from twistedclient import SocketClientFactory
from twisted.words.protocols import irc
from twisted.internet import protocol

class qttmwirc_conn(irc.IRCClient):
  nickname = "qttmwirc"
  def signedOn(self):
    print "signed on"
  def privmsg(self, user, channel, msg):
    print "privmsg:", [user, channel, msg]

class qttmwirc_factory(protocol.ClientFactory):
  def __init__(self):
      pass
  def buildProtocol(self, addr):
      p = qttmwirc_conn()
      p.factory = self
      return p

  def clientConnectionLost(self, connector, reason):
      """If we get disconnected, reconnect to server."""
      connector.connect()

  def clientConnectionFailed(self, connector, reason):
      print "connection failed:", reason
      reactor.stop()

instance = qttmwirc_factory()

class qttmwirc_gui(QMainWindow):
    def __init__(self, reactor, parent=None):
        super(qttmwirc_gui, self).__init__(parent)
        self.reactor = reactor

    def closeEvent(self, event):
      reactor.stop()

    def lastWindowClosed(self, *args):
      print "last windo closed"


app = QApplication(sys.argv)


from twisted.internet import reactor
mainwindow = qttmwirc_gui(reactor)
mainwindow.showMaximized()

reactor.connectTCP("irc.freenode.net", 6667, instance)

reactor.run()
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20150522/9b0db36a/attachment.html>


More information about the PyQt mailing list