本文整理汇总了C++中QDeclarativeContext::setContextObject方法的典型用法代码示例。如果您正苦于以下问题:C++ QDeclarativeContext::setContextObject方法的具体用法?C++ QDeclarativeContext::setContextObject怎么用?C++ QDeclarativeContext::setContextObject使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QDeclarativeContext
的用法示例。
在下文中一共展示了QDeclarativeContext::setContextObject方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: _q_sourceLoaded
void QDeclarativeLoaderPrivate::_q_sourceLoaded()
{
Q_Q(QDeclarativeLoader);
if (component) {
if (!component->errors().isEmpty()) {
QDeclarativeEnginePrivate::warning(qmlEngine(q), component->errors());
emit q->sourceChanged();
emit q->statusChanged();
emit q->progressChanged();
return;
}
QDeclarativeContext *creationContext = component->creationContext();
if (!creationContext) creationContext = qmlContext(q);
QDeclarativeContext *ctxt = new QDeclarativeContext(creationContext);
ctxt->setContextObject(q);
QDeclarativeGuard<QDeclarativeComponent> c = component;
QObject *obj = component->beginCreate(ctxt);
if (component != c) {
// component->create could trigger a change in source that causes
// component to be set to something else. In that case we just
// need to cleanup.
if (c)
c->completeCreate();
delete obj;
delete ctxt;
return;
}
if (obj) {
item = qobject_cast<QGraphicsObject *>(obj);
if (item) {
QDeclarative_setParent_noEvent(ctxt, obj);
QDeclarative_setParent_noEvent(item, q);
item->setParentItem(q);
// item->setFocus(true);
initResize();
} else {
qmlInfo(q) << QDeclarativeLoader::tr("Loader does not support loading non-visual elements.");
delete obj;
delete ctxt;
}
} else {
if (!component->errors().isEmpty())
QDeclarativeEnginePrivate::warning(qmlEngine(q), component->errors());
delete obj;
delete ctxt;
source = QUrl();
}
component->completeCreate();
emit q->sourceChanged();
emit q->statusChanged();
emit q->progressChanged();
emit q->itemChanged();
emit q->loaded();
}
}
示例2: sourceLoaded
//! [3]
void Loader::sourceLoaded()
{
if (m_component) { // Sanity check
/**
* If an error occured during loading, just emit the change notification
* signals, the 'status' property will reflect that error state.
*/
if (!m_component->errors().isEmpty()) {
emit statusChanged();
emit progressChanged();
emit sourceChanged();
emit controlChanged();
return;
}
// Get the declarative context of the declarative component
QDeclarativeContext *creationContext = m_component->creationContext();
// If it has not been set, use the declarative context of the Loader element as fallback
if (!creationContext)
creationContext = QDeclarativeEngine::contextForObject(this);
// Create a new child context that will be used as declarative context for the Cascades object
QDeclarativeContext *ctxt = new QDeclarativeContext(creationContext);
ctxt->setContextObject(this);
// Load the Cascades object
QObject *object = m_component->create(ctxt);
if (object) {
m_control = qobject_cast<bb::cascades::Control*>(object);
if (m_control) {
// If the loaded Cascades object is a Control, we use it as root element for the Loader and make it visible
setRoot(m_control);
setVisible(true);
} else {
// Otherwise report an error
qmlInfo(this) << tr("Loader does not support loading non-visual elements.");
delete object;
delete ctxt;
}
} else {
// Cleanup if the loading failed
delete object;
delete ctxt;
m_source = QUrl();
}
emit sourceChanged();
emit statusChanged();
emit progressChanged();
emit controlChanged();
emit loaded();
}
}
示例3: PropertyEditorTransaction
PropertyEditor::NodeType::NodeType(PropertyEditor *propertyEditor) :
m_view(new DeclarativeWidgetView), m_propertyEditorTransaction(new PropertyEditorTransaction(propertyEditor)), m_dummyPropertyEditorValue(new PropertyEditorValue()),
m_contextObject(new PropertyEditorContextObject())
{
Q_ASSERT(QFileInfo(":/images/button_normal.png").exists());
QDeclarativeContext *ctxt = m_view->rootContext();
m_view->engine()->setOutputWarningsToStandardError(debug);
m_dummyPropertyEditorValue->setValue("#000000");
ctxt->setContextProperty("dummyBackendValue", m_dummyPropertyEditorValue.data());
m_contextObject->setBackendValues(&m_backendValuesPropertyMap);
ctxt->setContextObject(m_contextObject.data());
connect(&m_backendValuesPropertyMap, SIGNAL(valueChanged(QString,QVariant)), propertyEditor, SLOT(changeValue(QString)));
}
示例4: handleViewportChange
void AbstractDataPlugin::handleViewportChange( const ViewportParams *viewport )
{
QList<AbstractDataPluginItem*> orphane = d->m_delegateInstances.keys();
QList<AbstractDataPluginItem*> const items = d->m_model->items( viewport, numberOfItems() );
foreach( AbstractDataPluginItem* item, items ) {
qreal x, y;
Marble::GeoDataCoordinates const coordinates = item->coordinate();
bool const visible = viewport->screenCoordinates( coordinates.longitude(), coordinates.latitude(), x, y );
if ( !d->m_delegateInstances.contains( item ) ) {
if ( !visible ) {
// We don't have, but don't need it either. Shouldn't happen though as the model checks for it already.
continue;
}
// Create a new QML object instance using the delegate as the factory. The original
// data plugin item is set as the context object, i.e. all its properties are available
// to QML directly with their names
QDeclarativeContext *context = new QDeclarativeContext( qmlContext( d->m_delegate ) );
context->setContextObject( item );
QList<QByteArray> const dynamicProperties = item->dynamicPropertyNames();
foreach( const QByteArray &property, dynamicProperties ) {
context->setContextProperty( property, item->property( property ) );
}
QObject* component = d->m_delegate->create( context );
QDeclarativeItem* newItem = qobject_cast<QDeclarativeItem*>( component );
QGraphicsItem* graphicsItem = qobject_cast<QGraphicsItem*>( component );
if ( graphicsItem && newItem ) {
graphicsItem->setParentItem( d->m_delegateParent );
}
if ( newItem ) {
d->m_delegateInstances[item] = newItem;
} else {
mDebug() << "Failed to create delegate";
continue;
}
} else if ( !visible ) {
示例5: main
Q_DECL_EXPORT int main(int argc, char *argv[])
{
qmlRegisterType<Dict>("Vortaro", 1, 0, "Dict");
qmlRegisterType<Word>("Vortaro", 1, 0, "Word");
QScopedPointer<QApplication> app(createApplication(argc, argv));
QmlApplicationViewer viewer;
QDeclarativeEngine *engine = viewer.engine();
QDeclarativeContext *rootContext = engine->rootContext();
// engine->addImportPath(QString("/opt/nokia/qtsdk/Simulator/Qt/gcc/imports"));
Session session;
session.load();
rootContext->setContextObject(&session);
viewer.setOrientation(QmlApplicationViewer::ScreenOrientationLockPortrait);
viewer.setSource(QUrl("qrc:///qml/main.qml"));
// viewer.setMainQmlFile(QString("qml/main.qml"));
viewer.showExpanded();
return app->exec();
}