Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. PySide 2 Sample application doesn't quit!
Qt 6.11 is out! See what's new in the release blog

PySide 2 Sample application doesn't quit!

Scheduled Pinned Locked Moved Solved QML and Qt Quick
8 Posts 2 Posters 2.4k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    nullbuil7
    wrote on last edited by nullbuil7
    #1

    Python Source:

    import sys
    from PySide2.QtGui import QGuiApplication
    from PySide2.QtCore import QCoreApplication, Qt, QUrl
    from PySide2.QtQuick import QQuickView
    
    QCoreApplication.setAttribute(Qt.AA_EnableHighDpiScaling)
    app = QGuiApplication(sys.argv)
    
    view = QQuickView(QUrl('view.qml'))
    view.show()
    
    app.exec_()
    sys.exit(0)
    
    
    
    
    

    QML file:

    import QtQuick 2.3
    import QtQuick.Controls 1.4
    
    Rectangle {
        width: 200
        height: 200
        color: "green"
    
        Button {
            text: "Hello World"
            anchors.centerIn: parent
            onClicked: Qt.quit()
        }
    }
    
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      What version of Qt ?
      On what OS ?
      How did you install Qt ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • N Offline
        N Offline
        nullbuil7
        wrote on last edited by nullbuil7
        #3

        Qt 5.5.1 (MSVC 2013, 32bit)
        Windows 10 Pro 64bit
        i got qt from a website that had an offline version build against mingw
        and i installed PySide2 using Python 3 pip module

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          I forgot: what version of PySide2 did you get with pip ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • N Offline
            N Offline
            nullbuil7
            wrote on last edited by
            #5

            PySide2 version is 5.12.3
            shiboken2 version is 5.12.3
            they both are for py3.7-win-amd64

            1 Reply Last reply
            0
            • N Offline
              N Offline
              nullbuil7
              wrote on last edited by
              #6

              Update on the situation i ran the code through command prompt directly and i received this error when i clicked the button:

              Signal QQmlEngine::quit() emitted, but no receivers connected to handle it.
              

              i googled the problem and it seems Qt has a new syntax and for this to work, I have to somehow make a connection between my .py and .qml file.

              sorry for the late reply. I HAVE TO WAIT 600 SECONDS :D

              1 Reply Last reply
              0
              • N Offline
                N Offline
                nullbuil7
                wrote on last edited by nullbuil7
                #7

                The docs notes:

                    quit()
                
                This function causes the QQmlEngine::quit() signal to be emitted. Within the Prototyping with qmlscene, this causes the launcher application to exit; to quit a C++ application when this method is called, connect the QQmlEngine::quit() signal to the QCoreApplication::quit() slot.
                
                

                Clearly point out that you have to connect the QQmlEngine::quit() of QQuickView to QCoreApplication::quit():

                import os
                import sys
                
                from PySide2.QtCore import QCoreApplication, Qt, QUrl
                from PySide2.QtGui import QGuiApplication
                from PySide2.QtQuick import QQuickView
                
                if __name__ == '__main__':
                    QCoreApplication.setAttribute(Qt.AA_EnableHighDpiScaling)
                    app = QGuiApplication(sys.argv)
                
                    current_dir = os.path.dirname(os.path.realpath(__file__))
                    filename = os.path.join(current_dir, 'view.qml')
                    view = QQuickView(QUrl.fromLocalFile(filename))
                    view.engine().quit.connect(QCoreApplication.quit)           <---
                    view.show()
                
                    sys.exit(app.exec_())
                

                Credits to eyllanesc
                https://stackoverflow.com/questions/57581974/qt-error-signal-qqmlenginequit-emitted-but-no-receivers-connected-to-handl

                1 Reply Last reply
                1
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  Glad you found out and thanks for sharing !

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  0

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved