I am creating a new window through the following code:
QMainController* myController = new QMainController(0,m_autenticado);
QQmlApplicationEngine* engine = new QQmlApplicationEngine(this);
engine->rootContext()->setContextProperty("MyController", myController);
engine->load(QUrl(QStringLiteral("qrc:///newPage.qml")));
QQuickWindow* window = qobject_cast<QQuickWindow*>(engine->rootObjects().at(0));
window->showFullScreen();
This code sets a MyController property to the rootContext, which means that all the pages at the root context will have access to this property. And so, this won't allow me to open 2 different windows from the same QML file, each with its own instance of MainController.
QUESTION: How can I bind this MyController property to the QQuickWindow context instead of the engine's rootContext?
I've tried to use a QQuickView and doing like this:
QMainController* myController = new QMainController(0,m_autenticado);
QQuickView* view = new QQuickView();
view->rootContext()->setContextProperty("MyController", myController );
view->setSource(QUrl(QStringLiteral("qrc:///main.qml")));
view->showFullScreen();
But I was complained with the following message:
"QQuickView only supports loading of root objects that derive from QQuickItem.
If your example is using QML 2, (such as qmlscene) and the .qml file you loaded has 'import QtQuick 1.0' or 'import Qt 4.7', this error will occur.
To load files with 'import QtQuick 1.0' or 'import Qt 4.7', use the QDeclarativeView class in the Qt Quick 1 module."