[Qt-qml] How to create/display items in a QDeclarativeView
Simon Pasch
fpasch at googlemail.com
Mon Jul 19 10:21:46 CEST 2010
Hello,
I'm currently trying to create and display qml-objects from C++ (As
you stated on http://doc.qt.nokia.com/4.7-snapshot/qdeclarativedynamicobjects.html
this is the preferred method for hybrid qml/c++ applications)
Therefore I create a QDeclarativeView from a base-qml-file (containing
the items displayed all the time. The base item is a rectangle).
QDeclarativeView *m_view = new QDeclarativeView();
m_view->setSource(QUrl::fromLocalFile("Base.qml"));
m_view->show();
On specific events (on the c++ side) I want to display a dialog within
this view. Currently I'm using the following code:
QDeclarativeComponent component(m_view->engine(),
QUrl::fromLocalFile("Dialog.qml"));
QDeclarativeItem *myItem = qobject_cast<QDeclarativeItem*>(component.create());
myItem->setParentItem(qobject_cast<QDeclarativeItem*>(m_view->rootObject()));
Is this the best approach to create dynamic objects from c++?
Regards
Simon
More information about the Qt-qml
mailing list