import os import sys from PySide2.QtCore import QObject, Slot from PySide2.QtQml import QQmlApplicationEngine, qmlRegisterType from PySide2.QtGui import QGuiApplication, QVector3D class DemoClass(QObject): def __init__(self, parent: QObject = None): super().__init__(parent) @staticmethod @Slot(QVector3D, result=bool) def call_static(vec: QVector3D) -> bool: return vec.isNull() @Slot(QVector3D, result=bool) def call_self(self, vec: QVector3D) -> bool: return vec.isNull() if __name__ == "__main__": app = QGuiApplication(sys.argv) # Set application basic info, this will allow QSettings and other Qt behavior app.setApplicationName("myapp") app.setApplicationDisplayName("My App") app.setOrganizationDomain("com.amotus.myapp") app.setOrganizationName("Amotus") # Add controllers to qml application engine engine = QQmlApplicationEngine() # There is no qmlRegisterSingletonType, so we cannot declare the class as singleton from python :-( qmlRegisterType(DemoClass, 'DemoModule', 1, 0, 'DemoClass') #Load the QML file engine.load('main.qml') #Show the window if not engine.rootObjects(): sys.exit(-1) sys.exit(app.exec_())