Uploaded image for project: 'Qt for Python'
  1. Qt for Python
  2. PYSIDE-2415

QQmlComponent cannot be used as a property type in Python

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P2: Important
    • 6.2.9, 6.6.0
    • 6.5.1, 6.4.3
    • PySide
    • None
    • Python 3.11.3
      Linux 6.4.8-arch1-1 x86_64
    • Linux/X11
    • 37cbce964 (dev), 1f599464a (6.5), ea2c43bc4 (tqtc/lts-6.2)

    Description

      Subclass QObject or a derived type with a property of type QQmlComponent:

      from PySide6.QtCore import Property, QObject
      from PySide6.QtQml import QQmlComponent
      
      class WithComponent(QObject):
          def get_component(self) -> QQmlComponent | None:
              return None
      
          component = Property(QQmlComponent, fget=get_component)
      

      Inspect the meta property:

      m = WithComponent.staticMetaObject
      c = m.property(m.indexOfProperty("component"))
      
      print("Type ID:", c.typeId())
      print("Type name:", c.typeName())
      print("Metatype is valid:", c.metaType().isValid())
      

      which yields

      Type ID: 0
      Type name: QQmlComponent*
      Metatype is valid: False
      

      I'd expect to be able to use this property but the type is not valid and cannot be used in QML. I've tried other types such as QObject or QQuickItem and they do work.

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            crmaurei Cristian Maureira-Fredes
            macph Ewan Macpherson
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes