Return a plain QMetaObject* from toDynamicMetaObject()
The only place where we use it, we swiftly cast it to QMetaObject* anyway. Generating an object with virtual methods, only to then cast to its non-virtual base type is dangerous. Also, if we are required to return a QAbstractDynamicMetaObject from a method of QDynamicMetaObjectData, we cannot implement QDynamicMetaObjectData without also implementing QAbstractDynamicMetaObject. This indirectly forces us to copy metaobjects around as we cannot wrap an existing metaobject into a QDynamicMetaObjectData subclass. Copying metaobjects around makes QMetaObject::inherits() unusable because inherits() assumes identity is determined by identity of the pointer. Change-Id: Icbe697efa6fd66649eef3c91260c95cda62e3c90 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
This commit is contained in:
parent
1453f048f5
commit
5d17487723
@ -111,6 +111,9 @@ public:
|
||||
int postedEvents;
|
||||
QDynamicMetaObjectData *metaObject;
|
||||
QBindingStorage bindingStorage;
|
||||
|
||||
// ### Qt7: Make this return a const QMetaObject *. You should not mess with
|
||||
// the metaobjects of existing objects.
|
||||
QMetaObject *dynamicMetaObject() const;
|
||||
|
||||
#ifdef QT_DEBUG
|
||||
|
@ -656,7 +656,7 @@ struct Q_CORE_EXPORT QDynamicMetaObjectData
|
||||
virtual ~QDynamicMetaObjectData();
|
||||
virtual void objectDestroyed(QObject *) { delete this; }
|
||||
|
||||
virtual QAbstractDynamicMetaObject *toDynamicMetaObject(QObject *) = 0;
|
||||
virtual QMetaObject *toDynamicMetaObject(QObject *) = 0;
|
||||
virtual int metaCall(QObject *, QMetaObject::Call, int _id, void **) = 0;
|
||||
};
|
||||
|
||||
@ -664,7 +664,7 @@ struct Q_CORE_EXPORT QAbstractDynamicMetaObject : public QDynamicMetaObjectData,
|
||||
{
|
||||
~QAbstractDynamicMetaObject();
|
||||
|
||||
QAbstractDynamicMetaObject *toDynamicMetaObject(QObject *) override { return this; }
|
||||
QMetaObject *toDynamicMetaObject(QObject *) override { return this; }
|
||||
virtual int createProperty(const char *, const char *) { return -1; }
|
||||
int metaCall(QObject *, QMetaObject::Call c, int _id, void **a) override
|
||||
{ return metaCall(c, _id, a); }
|
||||
|
Loading…
Reference in New Issue
Block a user