Search code examples
pyqtscrapypyqt4twistedreactor

QtReactor Closes Application Window (Using Scrapy)


I have setup a basic QT (PyQt4) application. It runs a couple of spiders using Scrapy and to avoid blocking the gui during what is a pretty lengthy scraping operation, I am using QtReactor (as I saw mentioned in a couple of places) to allow my GUI to update during scraping.

Right now I just have a spinning progress bar (range of 0,0) and it updates during scraping.

I have an issue, however, that once scraping is completing my application is exiting of its own accord. It's definitely related to QtReactor as without the first two lines of code added below, it works fine (but blocks GUI).

What's causing this?

Thanks.

My Main:

from qtreactor import pyqt4reactor
pyqt4reactor.install()

import sys
from PyQt4 import QtGui
from Gui.DkMainWindow import DkMainWindow

if __name__ == "__main__":

    app = QtGui.QApplication(sys.argv)

    form = DkMainWindow()
    form.show()
    sys.exit(app.exec_())

Solution

  • I have never used QtReactor, but all the examples I have seen do the install after creating the application:

    import sys
    from PyQt4 import QtGui
    from Gui.DkMainWindow import DkMainWindow
    
    if __name__ == "__main__":
    
        app = QtGui.QApplication(sys.argv)
    
        from qtreactor import pyqt4reactor
        pyqt4reactor.install()
    
        form = DkMainWindow()
        form.show()
        sys.exit(app.exec_())
    

    But if that makes no difference, you might also want to try:

        app.setQuitOnLastWindowClosed(False)