I am trying to switch between different QML files from C++. I use a QQMLApplicationEngine and I can load a new file using engine.load(filename)
Before I do this I close the current Window (QQuickWindow) using
QObject* pRootObject = in_pQmlApplicationEngine->rootObjects().first();
Q_ASSERT( pRootObject != NULL );
Q_ASSERT( pRootObject->objectName() == "mainWindow" );
QQuickWindow* pMainWindow = qobject_cast<QQuickWindow*>(pRootObject);
Q_ASSERT( pMainWindow );
pMainWindow->close();
which I found here: Properly reloading a QQmlApplicationEngine
This works, in the meaning that the window actually closes, but, and here comes the problem - the rootObject (from the QQMLApplicationEngine rootObjects) is not removed. So if I switch back and forth a few times the rootObjects list just grows.
Does anybody know what I am doing wrong?