QQuickWindow does not have its own context property, so there is no way to set a context property with it.
As the message explains, QQuickView expects a QML root object that inherits from QQuickItem , which means that root can be a Rectangle , Item , etc., but not ApplicationWindow or Window , since they are not inherited from QQuickItem . If you can change the root object to something like a Rectangle , you can create different instances of QQuickView to achieve your goal, since each QQuickView creates its own QQmlEngine , unless you provide an existing QQmlEngine for it.
QQmlApplicationEngine actually inherits from QQmlEngine , so each instance has its own root context. For example, calling the following createMain() twice will create two windows with separate engines, a separate controller and a separate rootContext:
void foo::createMain() { //TODO: Set a proper parent to myController 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(); }
If you are not sure about creating multiple copies of QQmlAppicationEngine , you can share one instance of QQmlApplicationEngine and create a child context for each instance of the window:
// foo.h class foo { private: QQmlApplicationEngine m_engine; // can change to QQmlEngine if you prefer } // foo.cpp void foo::createMain() { //TODO: Set a proper parent to myController QMainController* myController = new QMainController(0,m_autenticado); // Create a new context as a child of m_engine.rootContext() QQmlContext *childContext = new QQmlContext(&m_engine, &m_engine); childContext->setContextProperty("MyController", myController); QQmlComponent *component = new QQmlComponent(&m_engine, &m_engine); component->loadUrl(QUrl("qrc:///qml/newPage.qml")); // Create component in child context QObject *o = component->create(childContext); QQuickWindow* window = qobject_cast<QQuickWindow*>(o); window->show(); }
And of course, you can change QQmlApplication to QQmlEngine if there are no QQmlApplicationEngine features.