QMetaProperty::write behavior changed with Qt 5.6

  • I've written an ORM for Qt. With Qt5.6 I've run into a very special problem. The behavior of QMetaProperty::write has changed. It did work for me from Qt5 to Qt5.5, with 5.6 it is no longer working as intended.

    // working with Qt < 5.6, failing with Qt 5.6
     void EntityHelper::setListProperty(const QSharedPointer<Entity> &entity,
                                    QList<QSharedPointer<Entity>> &list,
                                    const QMetaProperty &property)  {
     QVariant var;
     property.write(entity.data(), var); //returns false and property attribute is not being changed - but it should be...

    Since Qt 5.6 this doesn't work anymore for QList<QSharedPointer<Entity>>.
    The problem seems to be related to such a list, as the following code (for single properties) still works:

    // single Entities are still being written - even with Qt 5.6
    void EntityHelper::setProperty(const QSharedPointer<Entity> &entity,
                               QSharedPointer<Entity> value,
                               const QMetaProperty &property) {
    if (value && value->getProperty(value->getPrimaryKey()).toLongLong()
            > -1) {
        QVariant var;
        property.write(entity.data(), var); //returns true, property is being changed

    A few explanations for a general understanding of where the code belongs to and what it should do:
    Every entity class inherits from my main "Entity" class. Entity inherits from QObject and uses the Q_OBJECT macro.
    Each Entity Object is wrapped by a QSharedPointer (to be on the safe side, memory-wise).
    Properties in the child classes are defined with the Q_PROPERTY macro.
    For example:

    // defining a property:
    Q_PROPERTY(QSharedPointer<Person> mainTeacher READ getMainTeacher WRITE
    // defining a list property:
    Q_PROPERTY(QList<QSharedPointer<Person>> persons READ
               getPersons WRITE setPersons)

    (You can find the code here: https://github.com/Professi/cuteentitymanager/blob/master/src/entityhelper.cpp)

    I've seen that some changes have been made to QMetaProperty::write since Qt5.5 https://github.com/qtproject/qtbase/blob/5.6/src/corelib/kernel/qmetaobject.cpp (Line 3038 ff.)

    I can't find a way to fix this problem. Is it a bug or a feature? Does anybody have an idea for a workaround?

  • Hi, and welcome to the Qt forum!

    Looks like a bug to me. I think you should talk to the developers on the interest mailing list.