Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Adding QML to QMdiArea as subwindow

Adding QML to QMdiArea as subwindow

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 3 Posters 2.7k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    davidesalvetti
    wrote on last edited by davidesalvetti
    #1

    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.

    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by VRonin
      #2

      @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

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      D 1 Reply Last reply
      0
      • VRoninV VRonin

        @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

        D Offline
        D Offline
        davidesalvetti
        wrote on last edited by
        #3

        @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.

        1 Reply Last reply
        0
        • VRoninV Offline
          VRoninV Offline
          VRonin
          wrote on last edited by VRonin
          #4

          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();
          

          "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
          ~Napoleon Bonaparte

          On a crusade to banish setIndexWidget() from the holy land of Qt

          D 1 Reply Last reply
          1
          • VRoninV VRonin

            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();
            
            D Offline
            D Offline
            davidesalvetti
            wrote on last edited by
            #5

            @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]
                       }
                 }
            }
            
            1 Reply Last reply
            0
            • VRoninV Offline
              VRoninV Offline
              VRonin
              wrote on last edited by
              #6

              can you try:

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

              "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
              ~Napoleon Bonaparte

              On a crusade to banish setIndexWidget() from the holy land of Qt

              D 1 Reply Last reply
              1
              • VRoninV VRonin

                can you try:

                • re running qmake
                • use just a very simple QML source. just a single text for example
                D Offline
                D Offline
                davidesalvetti
                wrote on last edited by
                #7

                @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.

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  Hi,

                  What about QQuickWidget ?

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  0

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved