I have a requirement for my project to display two QML Window
s each on one of the screen (one sender, one receiver). Both of the .qml
requires me to include some Cpp models inside hence, I'm using QQmlApplicationEngine
to register the Cpp models.
I found out that using QWidget::createWindowContainer()
I'm able to display multiple Window
s for a single project. This works perfectly fine for the first QML file. The code snippets looks like this:
QQmlApplicationEngine* engine = new QQmlApplicationEngine(Qurl("main.qml"));
QmlContext* context = engine.getContextProperty();
//do some Cpp models registering...
QQuickview *view = new QQuickview(engine,0);
QWidget* container = widget::createWindowContainer(view);
//I realized I dont need to do container->show(); for the main.qml to appear..
//use desktop widget to move the 2nd container to the 2nd screen...
I decided to create a 2nd application engine for my receive.qml
with a similar method. I soon realized that the receive.qml
would never open even with container2->show()
. Now, it is showing an empty page.
My questions are:
So if you need to open two schedules side by side the only way to achieve this is to use the 'Arrange All' button in the 'Window' section of the 'View' Ribbon. This will display all open schedules side by side in the same instance of Microsoft Project.
To optimize your screen space and your productivity, hover over a window's maximize button or select a window and press Win+Z, then choose a snap layout. Use Snap to arrange all your open windows using the mouse, keyboard, or the Snap Assist feature.
First, open the application you want to run in multiple instances. Then, hold down the Shift key on your keyboard and click with your cursor - or tap with your finger - on its taskbar icon. One click or tap opens a new instance, two clicks or taps open two, and so on.
That can be done easier, for example:
main.qml
import QtQuick 2.3
import QtQuick.Window 2.2
Item {
Window {
objectName: "wnd1"
visible: true
}
Window {
objectName: "wnd2"
visible: true
}
}
And so you can access these windows from C++ code:
main.cpp
QQmlApplicationEngine engine;
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
QQuickWindow *wnd1 = engine.rootObjects()[0]->findChild<QQuickWindow *>("wnd1");
if(wnd1)
wnd1->setTitle("Server");
QQuickWindow *wnd2 = engine.rootObjects()[0]->findChild<QQuickWindow *>("wnd2");
if(wnd2)
wnd2->setTitle("Client");
To catch a closing event you should use QQuickWindow::closing event
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With