import os
import sys
from PySide6.QtCore import QObject, QUrl
from PySide6.QtGui import QGuiApplication
from PySide6.QtQuick import QQuickView

def sayThis(s):

if __name__ == '__main__':
    app = QGuiApplication(sys.argv)
    view = QQuickView()
    qmlFile = os.path.join(os.path.dirname(__file__), 'view.qml')
    if view.status() == QQuickView.Error:

    root = view.rootObject()
    button = root.findChild(QObject, "buttonMouseArea")
    button.clicked.connect(lambda: sayThis("clicked button (signal directly connected)"))
    res = app.exec_()
    # Deleting the view before it goes out of scope is required to make sure all child QML instances
    # are destroyed in the correct order.
    del view


import QtQuick 2.0

Rectangle {
    id: page

    width: 500; height: 200
    color: "lightgray"

    Rectangle {
        id: button
        width: 150; height: 40
        color: "darkgray"
        anchors.horizontalCenter: page.horizontalCenter
        anchors.verticalCenter: page.verticalCenter
        MouseArea {
            id: buttonMouseArea
            objectName: "buttonMouseArea"
            anchors.fill: parent
        Text {
            id: buttonText
            text: "Press me!"
            anchors.horizontalCenter: button.horizontalCenter
            anchors.verticalCenter: button.verticalCenter
            font.pointSize: 16