I'm trying to use @QmlSingleton to manage my global variables in python. According to the documentation I only need to use @QmlElement followed by @QmlSingleton so that QQmlEngine will try to create a singleton instance using the type’s default constructor. This is the code so far:
QML_IMPORT_NAME = "g1.backend.main"
QML_IMPORT_MAJOR_VERSION = 1
@QmlElement
@QmlSingleton
class MySingleton(QObject):
def __init__(self):
self.folderPath = scriptDir + os.path.sep + '\\temp\\'
@Slot(result=str)
def getArea(self):
return self.folderPath