Exemple #1
0
/*!
    Set the \a value of the \a name property on this context.

    QQmlContext does \b not take ownership of \a value.
*/
void QQmlContext::setContextProperty(const QString &name, QObject *value)
{
    Q_D(QQmlContext);
    if (d->notifyIndex == -1)
        d->notifyIndex = QMetaObjectPrivate::absoluteSignalCount(&QQmlContext::staticMetaObject);

    QQmlContextData *data = d->data;

    if (data->isInternal) {
        qWarning("QQmlContext: Cannot set property on internal context.");
        return;
    }

    if (!isValid()) {
        qWarning("QQmlContext: Cannot set property on invalid context.");
        return;
    }

    QV4::IdentifierHash<int> &properties = data->detachedPropertyNames();
    int idx = properties.value(name);

    if (idx == -1) {
        properties.add(name, data->idValueCount + d->propertyValues.count());
        d->propertyValues.append(QVariant::fromValue(value));

        data->refreshExpressions();
    } else {
        d->propertyValues[idx] = QVariant::fromValue(value);
        QMetaObject::activate(this, d->notifyIndex, idx, 0);
    }
}
Exemple #2
0
/*!
    Set the context \a object.
*/
void QQmlContext::setContextObject(QObject *object)
{
    Q_D(QQmlContext);

    QQmlContextData *data = d->data;

    if (data->isInternal) {
        qWarning("QQmlContext: Cannot set context object for internal context.");
        return;
    }

    if (!isValid()) {
        qWarning("QQmlContext: Cannot set context object on invalid context.");
        return;
    }

    data->contextObject = object;
    data->refreshExpressions();
}