Minimal map qml example in QWidget application
-
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?
-
Hi,
What if you use QQuickWidget directly ?
-
What do you mean?
This?setCentralWidget(mView);
It doesn't work,
setCentralWidget()
only acceptQWidget*
params.
If I cast it toQWidget*
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.
-
Rather than make the QQuickView danse, directly use QQuickWidget.
-
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. -
Might be a silly question but are you including the proper modules in your
.pro
file ?