Multiple windows in a single project

后端 未结 1 1743
自闭症患者
自闭症患者 2021-02-14 18:35

I have a requirement for my project to display two QML Windows each on one of the screen (one sender, one receiver). Both of the .qml requires me to in

1条回答
  •  广开言路
    2021-02-14 19:05

    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("wnd1");
        if(wnd1)
            wnd1->setTitle("Server");
        QQuickWindow *wnd2 = engine.rootObjects()[0]->findChild("wnd2");
        if(wnd2)
            wnd2->setTitle("Client");
    

    To catch a closing event you should use QQuickWindow::closing event

    0 讨论(0)
提交回复
热议问题