Q_GLOBAL_STATIC(QDeclarativeValueTypeFactory, qmlValueTypes);
+QDeclarativeContextData *QDeclarativePropertyPrivate::effectiveContext() const
+{
+ if (context) return context;
+ else if (engine) return QDeclarativeContextData::get(engine->rootContext());
+ else return 0;
+}
+
void QDeclarativePropertyPrivate::initProperty(QObject *obj, const QString &name)
{
if (!obj) return;
return 0;
if (d->isValueType()) {
- QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(d->context);
+ QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(d->engine);
QDeclarativeValueType *valueType = 0;
if (ep) valueType = ep->valueTypes[d->core.propType];
else valueType = QDeclarativeValueTypeFactory::valueType(d->core.propType);
{
if (isValueType()) {
- QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(context);
+ QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(engine);
QDeclarativeValueType *valueType = 0;
if (ep) valueType = ep->valueTypes[core.propType];
else valueType = QDeclarativeValueTypeFactory::valueType(core.propType);
bool rv = false;
if (isValueType()) {
- QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(context);
+ QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(engine);
QDeclarativeValueType *writeBack = 0;
if (ep) {
data.setFlags(valueType.flags);
data.coreIndex = valueType.valueTypeCoreIdx;
data.propType = valueType.valueTypePropType;
- rv = write(writeBack, data, value, context, flags);
+ rv = write(writeBack, data, value, effectiveContext(), flags);
writeBack->write(object, core.coreIndex, flags);
if (!ep) delete writeBack;
} else {
- rv = write(object, core, value, context, flags);
+ rv = write(object, core, value, effectiveContext(), flags);
}
// Bugs
void crashOnValueProperty();
void aliasPropertyBindings();
+ void noContext();
void copy();
private:
QCOMPARE(p2.propertyType(), (int)QVariant::Int);
}
+void tst_qdeclarativeproperty::noContext()
+{
+ QDeclarativeComponent compA(&engine, TEST_FILE("NoContextTypeA.qml"));
+ QDeclarativeComponent compB(&engine, TEST_FILE("NoContextTypeB.qml"));
+
+ QObject *a = compA.create();
+ QVERIFY(a != 0);
+ QObject *b = compB.create();
+ QVERIFY(b != 0);
+
+ QVERIFY(QDeclarativeProperty::write(b, "myTypeA", QVariant::fromValue(a), &engine));
+
+ delete a;
+ delete b;
+}
+
void tst_qdeclarativeproperty::initTestCase()
{
qmlRegisterType<MyQmlObject>("Test",1,0,"MyQmlObject");
qmlRegisterType<MyContainer>("Test",1,0,"MyContainer");
}
-
QTEST_MAIN(tst_qdeclarativeproperty)
#include "tst_qdeclarativeproperty.moc"