Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Minimal map qml example in QWidget application
Forum Updated to NodeBB v4.3 + New Features

Minimal map qml example in QWidget application

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
6 Posts 2 Posters 614 Views 2 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.
  • DragoonD Offline
    DragoonD Offline
    Dragoon
    wrote on last edited by
    #1

    Inspired by the minimal map example I'm trying to embeed a qml map inside a standard QWidget application.
    I defined the following qml script (map.qml):

    import QtQuick 2.15
    import QtLocation 5.6
    import QtPositioning 5.6
    
    Item {
       visible: true
       anchors.fill: parent
    
       Plugin {
           id: mapPlugin
           name: "osm"
       }
    
       Map {
           anchors.fill: parent
           plugin: mapPlugin
           center: QtPositioning.coordinate(44.17327, 9.87352)
           zoomLevel: 14
       }
    }
    

    Added the following method to Mainwindow class:

    void MainWindow::init_view(const QUrl& source)
    {
        mView = new QQuickView;
    
        mView->setSource(source);
    
        mWidget = QWidget::createWindowContainer(mView, this);
    
        setCentralWidget(mWidget);
    }
    

    Such method is called here (in main.cpp):

        MainWindow w;
        w.init_view(QUrl("qrc:/map.qml"));
        w.show();
    

    The app runs and correctly show the map (as did the original minimal map example), but looking into Application Output window I got this warning line:

    QObject::connect(QQuickWindow, QDeclarativeGeoMap): invalid nullptr parameter
    

    What's the problem? Do I need to worry about this?

    bye by[t]e{s}... Mike

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

      Hi,

      What if you use QQuickWidget directly ?

      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
      • DragoonD Offline
        DragoonD Offline
        Dragoon
        wrote on last edited by Dragoon
        #3

        What do you mean?
        This?

        setCentralWidget(mView);
        

        It doesn't work, setCentralWidget() only accept QWidget* params.
        If I cast it to QWidget* the application crashes with the following output:

        14:52:22: Starting build-maptest-Desktop_Qt_5_15_2_GCC_64bit-Debug/maptest...
        QML debugging is enabled. Only use this in a safe environment.
        QObject::connect(QQuickWindow, QDeclarativeGeoMap): invalid nullptr parameter
        14:52:23: build-maptest-Desktop_Qt_5_15_2_GCC_64bit-Debug/maptest crashed.
        

        bye by[t]e{s}... Mike

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

          Rather than make the QQuickView danse, directly use QQuickWidget.

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

          DragoonD 1 Reply Last reply
          0
          • SGaistS SGaist

            Rather than make the QQuickView danse, directly use QQuickWidget.

            DragoonD Offline
            DragoonD Offline
            Dragoon
            wrote on last edited by Dragoon
            #5

            @SGaist

            I tried with this:

            mView = new QQuickWidget;
            
            mView->setSource(source);
            mView->show();
            
            setCentralWidget(mView);
            

            Got the the same messages on application output as if I was using QQuickView (nullptr warning included), no application crash but no map was shown.

            bye by[t]e{s}... Mike

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

              Might be a silly question but are you including the proper modules in your .pro file ?

              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