qtinuum / QtnProperty

Extended properties for Qt5
Apache License 2.0
425 stars 153 forks source link

Cannot find default delegate for property "" #37

Closed Lishen1 closed 5 years ago

Lishen1 commented 5 years ago
QtnPropertyWidget* centralWidget;
QtnPropertySet* m_propertySet;
centralWidget = new QtnPropertyWidget();
m_propertySet = new QtnPropertySet(centralWidget);
layout()->addWidget(centralWidget);
centralWidget->setPropertySet(m_propertySet);
new QtnPropertyBool(m_propertySet); // this produce Cannot find default delegate for property "" Did you forget to register default delegate for  QtnPropertyBase type?

if i swap this lines

centralWidget->setPropertySet(m_propertySet);
new QtnPropertyBool(m_propertySet);

this problem is gone.

lexxmark commented 5 years ago

Yes, I can reproduce this.

It's because I'm adding property to property set in QtnPropertyBase constructor. At this time QtnPropertyBool object is not constructed yet so delegate factory looking delegate by QtnPropertyBase type.

In the second case delegate factory is working in the line

centralWidget->setPropertySet(m_propertySet);

and QtnPropertyBool object is fully constructed at this point.

There are two solutions there:

  1. Forbid adding properties to property set in constructor. So the next line
    boolProperty = new QtnPropertyBool(m_propertySet);

    won't work and you will have to do explicit call:

    m_propertySet->addChildProperty(boolProperty);
  2. Call qtnAddPropertyAsChild(parent, this, false); in each leaf property class constructor and throw some diagnostic if developer of the class did forget to call it.

Both solutions have caveats.

What do you think?

Lishen1 commented 5 years ago

for the first case i get error C2512: 'QtnPropertyBool': no appropriate default constructor available this case didnt work too

    _prop = new T(_prop_set);
    _prop_set->addChildProperty(_prop);
lexxmark commented 5 years ago

I meant I should change QtnProperty code to have solution 1 or 2. Now it doesn't work. I know.

I'm refactoring code now and ping you when done.

lexxmark commented 5 years ago

I have made some changes in the code. Now "new T(_prop_set);" doesn't adds new property to _prop_set. you have to choices: 1.

    _prop = new T(_prop_set);
    _prop_set->addChildProperty(_prop);

2.

    qtnCreateProperty<T>(_prop_set [, "property name"]);
Lishen1 commented 5 years ago

thank you, it works.