Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QMetaProperty::write behavior changed with Qt 5.6
Forum Update on Monday, May 27th 2025

QMetaProperty::write behavior changed with Qt 5.6

Scheduled Pinned Locked Moved Unsolved General and Desktop
qt5.6qmetatypeqmetaobjectqvariant
2 Posts 2 Posters 1.3k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • prophecyP Offline
    prophecyP Offline
    prophecy
    wrote on last edited by
    #1

    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;
     var.setValue<QList<QSharedPointer<Entity>>>(list);
     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;
        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.)

    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?

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      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.

      Cheers!

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved