Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-101359

Using QMetaProperty::read/writeOnGadget on QObjects

XMLWordPrintable

    • Icon: Suggestion Suggestion
    • Resolution: Won't Do
    • Icon: Not Evaluated Not Evaluated
    • None
    • 6.3.0 Beta1
    • None
    • All

      I recently used

      QtRemoteObjects::copyStoredProperties<T>(src, dst);

      with T subclassing QObject.

      This leads to an assertion error because copyStoredProperties internally uses QMetaProperty::read/writeOnGadget. Both access methods require PropertyAccessInStaticMetaCall to be set (i.e. only for Q_GADGET).

      Nevertheless, readOnGadget/writeOnGadget actually work fine even for QObjects after ignoring the assertion error. 

       

      My suggestion is to let readOnGadget and writeOnGadget accept QObjects by extending the assert expression in qmetaobject.cpp with an inheritance check:

       

      Q_ASSERT((priv(mobj->d.data)->flags & PropertyAccessInStaticMetaCall && mobj->d.static_metacall) || mobj->inherits(&QObject::staticMetaObject));

       
      In case, meta object is actually QObject subtype the following phantom cast to QObject pointer is ok:

      return read(reinterpret_cast<const QObject*>(gadget));

       This change will not have any effect for the default use case of reading and writing Q_GADGETs' properties.

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            thiago Thiago Macieira
            docjambi Peter Droste
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes