pyside6-metaobjectdump#

pyside6-metaobjectdump是一个命令行工具。它扫描Python源文件,并将要注册到QML中的类信息以JSON格式输出。这为pyside6-qmltyperegistrar工具提供输入。

该工具等同于Qt/C++中的moc工具。

在通过qmllint参数告诉它检查QML源文件时,该工具会由pyside6-project工具自动运行。

使用#

要注册到QML中的类由像@QmlElement这样的QML装饰器标识。调用

pyside6-metaobjectdump birthdayparty.py

将在标准输出上生成JSON数据

[
    {
        "classes": [
            {
                "className": "BirthdayParty",
                "qualifiedClassName": "BirthdayParty",
                "object": true,
                "superClasses": [
                    {
                        "access": "public",
                        "name": "QObject"
                    }
                ],
                "classInfos": [
                    {
                        "name": "QML.Element",
                        "value": "auto"
                    }
                ],
                "properties": [
                    {
                        "name": "host",
                        "type": "Person",
                        "index": 0,
                        "read": "host",
                        "notify": "host_changed",
                        "write": "host"
                    },
                    {
                        "name": "guests",
                        "type": "QQmlListProperty<Person>",
                        "index": 1
                    }
                ],
                "signals": [
                    {
                        "access": "public",
                        "name": "host_changed",
                        "arguments": [],
                        "returnType": "void"
                    },
                    {
                        "access": "public",
                        "name": "guests_changed",
                        "arguments": [],
                        "returnType": "void"
                    }
                ]
            }
        ],
        "outputRevision": 68,
        "QML_IMPORT_NAME": "People",
        "QML_IMPORT_MAJOR_VERSION": 1,
        "QML_IMPORT_MINOR_VERSION": 0,
        "QT_MODULES": [
            "QtCore",
            "QtQml"
        ],
        "inputFile": ".../examples/qml/tutorials/extending-qml-advanced/advanced1-Base-project/birthdayparty.py"
    }
]