我有一个项目的要求,需要在两个屏幕上分别显示两个QML窗口(一个发送方,一个接收方)。由于两个.qml文件都需要包含一些Cpp模型,因此我使用QQmlApplicationEngine来注册Cpp模型。
我发现使用QWidget::createWindowContainer()可以在单个项目中显示多个窗口。这对于第一个QML文件完全正常运行。代码片段如下:
我决定为我的
我的问题是:
我发现使用QWidget::createWindowContainer()可以在单个项目中显示多个窗口。这对于第一个QML文件完全正常运行。代码片段如下:
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...
我决定为我的
receive.qml
创建第二个应用程序引擎,使用类似的方法。但我很快意识到,即使使用container2->show()
,也无法打开receive.qml
。现在,它显示为空白页面。我的问题是:
- 我的方法正确吗?还是有更好的解决方案?
- 我需要注意哪个信号以捕获窗口关闭事件?当其中一个窗口关闭时,我似乎无法检测到该信号。因为我想要在其中一个被检测到时关闭两个窗口。