Adding QML to QMdiArea as subwindow



  • Hi guys,

    I have a satellite map in qml and what I need to do is just put into my existing MdiArea a subwindow that contains this qml satellite map.

    Here is my code

         //pWidget is a TabWidget that contains the MDIArea where I want to put my map   
        QDialog *dial = new QDialog(pWidget);      
    
        QQuickView *view = new QQuickView;
    
        QWidget *container = QWidget::createWindowContainer(view);
        container->setMinimumSize(200, 200);
        container->setMaximumSize(700, 700);
    
        QVBoxLayout *layout = new QVBoxLayout(dial);
        layout->setContentsMargins(0,0,0,0);
        layout->addWidget(container);            //I add the container widget where tha map should be into the layout
    
        view->setSource(QUrl("qrc:/qml/MapTrack.qml"));     //Set the qml map
    
        QMdiSubWindow *graf = pArea->addSubWindow(dial);   // I Create the subwindow, pArea is an MDIArea
        graf->show();
    

    When I run this code I see that another window is created but not into the MDIArea, then the program crushes.

    Debugging I get this error:

    "QML Debugger: Waiting for connection on port 50712...
    ASSERT: "!m_thread.isRunning()" in file qqmldebugserver.cpp, line 655"

    I really don't know what's wrong with this code, any help is appreciated.

    Thanks in advance.



  • @davidesalvetti said in Adding QML to QMdiArea as subwindow:

    QVBoxLayout *layout = new QVBoxLayout(container);
    layout->addWidget(container);

    You are trying to insert container inside its own layout.
    i guess you meant QVBoxLayout *layout = new QVBoxLayout(dial); and you are free to remove dial->setLayout(layout); once you did that



  • @VRonin Yeah, I'm sorry, I already found that error but I forgot to update my code.

    Anyway it still doesn't work: same error.
    I can't understand why.



  • Let's try narrowing down the problem:
    Try this and tell us if it works

     QDialog *dial = new QDialog;      
        QQuickView *view = new QQuickView;
        QWidget *container = QWidget::createWindowContainer(view);
        QVBoxLayout *layout = new QVBoxLayout(dial);
        layout->addWidget(container);
        view->setSource(QUrl("qrc:/qml/MapTrack.qml"));
    dial->exec();
    dial->deleteLater();
    


  • @VRonin said in Adding QML to QMdiArea as subwindow:

    QDialog *dial = new QDialog;
    QQuickView *view = new QQuickView;
    QWidget *container = QWidget::createWindowContainer(view);
    QVBoxLayout *layout = new QVBoxLayout(dial);
    layout->addWidget(container);
    view->setSource(QUrl("qrc:/qml/MapTrack.qml"));
    dial->exec();
    dial->deleteLater();

    Same error.
    Debugging I found that the program crushes when executing the:

    view->setSource(QUrl("qrc:/qml/MapTrack.qml"));
    

    I'm wondering if the program doesn't see the resource file but I don't know why. This is the Resources structure. I simply click the right button on MapTrack.qml and I get the URL I use.

    ![alt text](0_1515582201704_img_rsc.PNG image url)

    Maybe the problem is the QML file? This is the code:

    import QtQuick.Controls 1.4
    import QtQuick.Window 2.0
    import QtLocation 5.6
    import QtPositioning 5.6
    
    Window {
        id: mainWindow
        width: 512
        height: 512
        visible: true
    
        ListModel{
            id:dummyModel
            ListElement {
                Latitude: 47.212047
                Longitude: -1.551647
                Label: "something"
                Orientation: 0
                Color:"transparent"
            }
       }
    
        Plugin {
            id: googleMaps
            name: "googlemaps" // "mapboxgl", "esri", ...
            // specify plugin parameters if necessary
            // PluginParameter {
            //     name:
            //     value:
            // }
    
        }
    
        Map {
            id: myMap
            anchors.fill: parent
            plugin: googleMaps
            activeMapType: supportedMapTypes[1]
    
            center: QtPositioning.coordinate(59.91, 10.75) // Oslo
            zoomLevel: 14
    
            MapItemView{
                id:dynamicMapObject
                model: dummyModel
                delegate: MapQuickItem {
                    coordinate: QtPositioning.coordinate(Latitude,Longitude)
                    sourceItem:  Text{
                        width: 100
                        height: 50
                        text: model.Label
                        rotation: model.Orientation
                        opacity: 0.6
                        color: model.Color
                    }
                }
            }
    
            MapPolyline {
                    line.width: 3
                    line.color: 'green'
                    path: [
                        { latitude: 59.92, longitude: 10.77 },
                        { latitude: 59.96, longitude: 10.78 },
                        { latitude: 59.99, longitude: 10.76 },
                        { latitude: 59.95, longitude: 10.74 }
                    ]
            }
    
            MapCircle {
              //a static item (fixed real dimension) always at 100m east of the map center
              id:prova
              center: myMap.center.atDistanceAndAzimuth(100,90)
              opacity:0.8
              color:"red"
              radius:30
    
            }
        }
    
        MouseArea {
               anchors.fill: parent
               acceptedButtons:  Qt.RightButton
    
               onClicked: {
                    if (mouse.button === Qt.RightButton)
                    {
    
                        dummyModel.append({
                            "Latitude": myMap.toCoordinate(Qt.point(mouseX,mouseY)).latitude ,"Longitude": myMap.toCoordinate(Qt.point(mouseX,mouseY)).longitude ,
                            "Label": "abc" , "Color": "red",
                            "Orientation":Number(3), })
                    }
               }
        }
    
        GroupBox{
               title:"map types"
               ComboBox{
                   model:myMap.supportedMapTypes
                   textRole:"description"
                   onCurrentIndexChanged: myMap.activeMapType = myMap.supportedMapTypes[currentIndex]
               }
         }
    }
    


  • can you try:

    • re running qmake
    • use just a very simple QML source. just a single text for example


  • @VRonin I made some test from my side. I tried both your suggestions but they didn't worked.
    Luckily I found a possible workaround that works.

    I have created a QDialog class like this:

    SatelliteMap::SatelliteMap(QWidget *parent) :
        QDialog(parent),
        ui(new Ui::SatelliteMap)
    {
        ui->setupUi(this);
        setAttribute(Qt::WA_DeleteOnClose);
    
        view = new QQuickView();
        view->setResizeMode(QQuickView::SizeRootObjectToView);
        container = QWidget::createWindowContainer(view, this);
        container->setFocusPolicy(Qt::TabFocus);
        view->setSource(QUrl("qrc:/qml/qml/MapTrack.qml"));
    
        ui->verticalLayout->addWidget(container);
    }
    

    After this I created a QMdiSubWindow of the QDialog above.
    I really don't understand why it works this way. Anyway Thanks for the attention.


  • Lifetime Qt Champion

    Hi,

    What about QQuickWidget ?


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.