Normally we set up a Qt application in this way:
QGuiApplication qtapp(argc, argv);
QQuickView rootView;
rootView.setResizeMode(QQuickView::SizeRootObjectToView);
rootView.setSource(QUrl("qrc:myfile.qml"));
rootView.show();
QQmlEngine * qmlEngine = view.engine();
QQmlComponent component(qmlEngine, QUrl("qrc:myview.qml"));
QQuickItem * qItem = qobject_cast<QQuickItem *>(component.create());
However, we would like to get rid of the external qml
files and pass the source code directly. This is possible for the QQuickItem
in this way:
QQmlEngine * qmlEngine = view.engine();
QQmlComponent component(qmlEngine);
component.setData("my source code here", QUrl());
QQuickItem * qItem = qobject_cast<QQuickItem *>(component.create());
However, we have not been able to do the same for the rootView
. How can we do that?