I have a component in an external QML file. The component is dynamically added like this:
QUrl url = QUrl (QStringLiteral ("qrc:///MyPage.qml"));
// Delete the current page.
qDeleteAll (m_pContentArea->children());
// Gain access to the engine and context.
QQmlEngine *pEngine = qmlEngine (m_pContentArea);
QQmlContext *pCtx = pEngine->contextForObject (m_pContentArea);
// Create the new component.
QQmlComponent component (pEngine, url);
QObject *pNewPage = component.beginCreate (pCtx);
// parent for the object hierarchy:
pNewPage->setParent (m_pContentArea);
// parent property for dynamic bindings:
pNewPage->setProperty ("parent", QVariant::fromValue<QObject *>(m_pContentArea));
// ...
component.completeCreate();
So far, so clear. I now basically would like to connect the contentArea’s property “height” to be the same as the page’s height, with the intention that if the page’s height changes, the contentArea’s height changes also.
To set the contentArea’s height to some constant value, I could write:
m_pContentArea->setProperty ("height", QVariant::fromValue<qreal>(1000.0f));
How can I set the value of the property to be a script? The following doesn’t work:
m_pContentArea->setProperty ("height", QVariant::fromValue<QString>QStringLiteral ("parent.height"));
I tried also:
QObject::connect (m_pContentArea, SIGNAL (setHeight (qreal)),
pNewPage, SLOT (height()));
But this doesn’t work either, because there is no signal called setHeight (qreal).
↧