开发者

self.exit and self.quit do not exit PyQt application

开发者 https://www.devze.com 2023-04-12 19:09 出处:网络
I\'m trying to write a开发者_开发百科 PyQt application that renders HTML, waits, and finishes. I\'ve got the rendering mostly down (but stripped out here for simplicity\'s sake). The code here runs an

I'm trying to write a开发者_开发百科 PyQt application that renders HTML, waits, and finishes. I've got the rendering mostly down (but stripped out here for simplicity's sake). The code here runs and hangs, it seems as if the self.exit call (or self.quit) is not being honored. Having no prior experience with Qt, I feel as if I'm missing something obvious. Can someone shed some light on this?

I've also tried putting the exit calls at the end of the render function.

from PyQt4.Qt import QApplication
from PyQt4.QtWebKit import QWebView
import sys

class ScreenshotterApplication(QApplication):

    def __init__(self, args, html):
        QApplication.__init__(self, args)

        self.browser = QWebView()
        self.render(html)
        self.exit()

    def render(self, html):
        print html

if __name__ == "__main__":
    app = ScreenshotterApplication(sys.argv, '<h1>Hello, World!</h1>')
    sys.exit(app.exec_())


I don't really understand what you are trying to do but, that said, you are calling exit (or quit) in the constructor of your QApplication. exit (or quit) tells the QApplication to leave its event loop, but in the constructor, the eventloop is not yet started (it is once exec_ is called).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号