[PyQt] PyQt 5.1 App doesn't exit after QQuickView closed

Phil Thompson phil at riverbankcomputing.com
Tue Aug 27 15:16:32 BST 2013


On Tue, 27 Aug 2013 09:26:55 +1200, Glenn Ramsey <gr at componic.co.nz>
wrote:
> Hi,
> 
> In the following example, the application doesn't exit after the
> QQuickView 
> window is closed. Is this the correct behaviour or is it a bug? This is
> using 
> snapshot-693a95fde3fa on OSX 10.8.4 with Qt 5.1, PyQt 5.1 and macports
> python 
> built as 32 bit.
> 
> Glenn
> 
> import sys
> import os
> 
> from PyQt5 import QtCore
> from PyQt5 import QtWidgets
> from PyQt5 import QtQuick
> 
> def main():
>      app = QtWidgets.QApplication(sys.argv)
>      quickview = QtQuick.QQuickView()
>      if getattr(sys, 'frozen', None):
>          basedir = sys._MEIPASS
>      else:
>          basedir = os.path.dirname(__file__)
>      quickview.setSource(QtCore.QUrl.fromLocalFile(os.path.join(basedir,

> 'hello.qml')))
>      quickview.show()
> 
>      app.exec_()
> 
> if __name__ == "__main__":
>      main()
> 
> 
> hello.qml:
> 
> import QtQuick 2.0
> 
> Rectangle {
>      width: 360
>      height: 360
>      Text {
>          anchors.centerIn: parent
>          text: "Hello World"
>      }
>      MouseArea {
>          anchors.fill: parent
>          onClicked: {
>              Qt.quit();
>          }
>      }
> }

You need to connect up the engine's quit() signal...

quickview.engine().quit.connect(app.quit)

Phil


More information about the PyQt mailing list