Hello,
The behavior of QMetaProperty::write has changed with 5.6.
In a
special situation it is no longer working as intended (by me). This
appears to be a show stopper for my project.
// 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;
var.setValue<QList<QSharedPointer<Entity>>>(list);
property.write(entity.data(), var); //returns false and property attribute is
not being changed - but it should be...
}
The problem seems to be related to Lists, 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;
var.setValue<QSharedPointer<Entity>>(value);
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
setMainTeacher)
// 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.)
The problem appears in a Linux environment (GCC/Clang) as well as in Windows
(MinGW).
I have already asked this question in the Qt Forum and was sent on to this
place.
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?
Best regards
Christian Ehringfeld
_______________________________________________
Interest mailing list
[email protected]
http://lists.qt-project.org/mailman/listinfo/interest