本文整理汇总了C++中QQmlContext::setContextObject方法的典型用法代码示例。如果您正苦于以下问题:C++ QQmlContext::setContextObject方法的具体用法?C++ QQmlContext::setContextObject怎么用?C++ QQmlContext::setContextObject使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QQmlContext
的用法示例。
在下文中一共展示了QQmlContext::setContextObject方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: contextSetObject
void contextSetObject(QQmlContext_ *context, QObject_ *value)
{
QQmlContext *qcontext = reinterpret_cast<QQmlContext *>(context);
QObject *qvalue = reinterpret_cast<QObject *>(value);
// Give qvalue an engine reference if it doesn't yet have one.
if (!qmlEngine(qvalue)) {
QQmlEngine::setContextForObject(qvalue, qcontext->engine()->rootContext());
}
qcontext->setContextObject(qvalue);
}
示例2: 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
QQmlContext *context = new QQmlContext( 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 );
QQuickItem* newItem = qobject_cast<QQuickItem*>( 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 ) {