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

Using QMetaProperty::read/writeOnGadget on QObjects

    XMLWordPrintable

    Details

    • Type: Suggestion
    • Status: Closed
    • Priority: Not Evaluated
    • Resolution: Won't Do
    • Affects Version/s: 6.3.0 Beta1
    • Fix Version/s: None
    • Labels:
      None
    • Platform/s:
      All

      Description

      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.

        Attachments

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

          Activity

            People

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

              Dates

              Created:
              Updated:
              Resolved:

                Gerrit Reviews

                There are no open Gerrit changes