PropertCache: Don't pass Q_GADGET value types as integers
We need to check for the IsGadget flag there. Fixes: QTBUG-73734 Change-Id: Ic4afd4215e6ed346bc40794d85397f0f262715e2 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
This commit is contained in:
parent
dbc811e164
commit
9343fbc478
|
@ -929,8 +929,8 @@ static bool passTypeAsInt(int type)
|
|||
if (type < int(QMetaType::User))
|
||||
return false;
|
||||
|
||||
// Pointers to QObjects and QGadgets can be handled as they are.
|
||||
if (flags & (QMetaType::PointerToQObject | QMetaType::PointerToGadget))
|
||||
// Pointers to QObjects and QGadgets, and QGadgets themselves can be handled as they are.
|
||||
if (flags & (QMetaType::PointerToQObject | QMetaType::PointerToGadget | QMetaType::IsGadget))
|
||||
return false;
|
||||
|
||||
// If it wasn't declared as metatype, better don't touch it.
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
import QtQml 2.2
|
||||
|
||||
QtObject {
|
||||
property var result;
|
||||
|
||||
property Connections connections: Connections {
|
||||
target: emitter
|
||||
onEmitGadget: function(gadget) {
|
||||
result = gadget.someProperty;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -50,6 +50,7 @@ private slots:
|
|||
void signalHandlers();
|
||||
void signalHandlersDerived();
|
||||
void passForeignEnums();
|
||||
void passQGadget();
|
||||
void metaObjectSize_data();
|
||||
void metaObjectSize();
|
||||
void metaObjectChecksum();
|
||||
|
@ -338,6 +339,44 @@ void tst_qqmlpropertycache::passForeignEnums()
|
|||
|
||||
Q_DECLARE_METATYPE(MyEnum::Option1)
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
class SimpleGadget
|
||||
{
|
||||
Q_GADGET
|
||||
Q_PROPERTY(bool someProperty READ someProperty)
|
||||
public:
|
||||
bool someProperty() const { return true; }
|
||||
};
|
||||
|
||||
// Avoids NeedsCreation and NeedsDestruction flags
|
||||
Q_DECLARE_TYPEINFO(SimpleGadget, Q_PRIMITIVE_TYPE);
|
||||
QT_END_NAMESPACE
|
||||
|
||||
class GadgetEmitter : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
signals:
|
||||
void emitGadget(SimpleGadget);
|
||||
};
|
||||
|
||||
void tst_qqmlpropertycache::passQGadget()
|
||||
{
|
||||
qRegisterMetaType<SimpleGadget>();
|
||||
|
||||
GadgetEmitter emitter;
|
||||
engine.rootContext()->setContextProperty("emitter", &emitter);
|
||||
QQmlComponent component(&engine, testFile("passQGadget.qml"));
|
||||
QVERIFY(component.isReady());
|
||||
|
||||
QScopedPointer<QObject> obj(component.create(engine.rootContext()));
|
||||
QVariant before = obj->property("result");
|
||||
QVERIFY(before.isNull());
|
||||
emit emitter.emitGadget(SimpleGadget());
|
||||
QVariant after = obj->property("result");
|
||||
QCOMPARE(QMetaType::Type(after.type()), QMetaType::Bool);
|
||||
QVERIFY(after.toBool());
|
||||
}
|
||||
|
||||
class TestClass : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
|
Loading…
Reference in New Issue