Important: Please read the Qt Code of Conduct -

Custom type Q property issue when derived type assigned

  • Hi,

    I have derived a class from QObject(say BaseProperty). Then I derived 2 classes from BaseProperty named DProp1 and DProp2.
    All the above 3 classes registerd to QML meta system using qmlRegisterType() API.

    Now i have a complex type class which contain a property with type BaseProperty*

    class MyMainItem : public QObject{
    Q_PROPRTY(BaseProperty* property READ getProp WRITE setProp)
    Then I registered this class as follows:
    qmlRegistertType<MyMainItem>( "MyTypes", 1, 0, "MyMainItem");

    In my QML i have added like...

    #import MyTypes 1.0
    MyMainItem {
    property: DProp1 {} /// Causes error
    property: BaseProperty{} /// Fine

    I can't set derived object to Base type property.
    I know it can done in some way similar like

    validator: IntValidator{bottom: 11; top: 31;} /// Work fine
    validator: DoubleValidator{bottom: 1.0; top: 2.0;} /// Work fine
    Please help. How to do that?

Log in to reply