I want to see map with cmake, qml. But it's not working
-
Hi for all!
I'm new to Qt so I think i'm losing something. But i don't know what's missing..
I'm using Qt 5.15.2 with MSVC 2019 64-bit, Windows 11
My CMakeLists.txt is
cmake_minimum_required(VERSION 3.16) project(Foo VERSION 0.1 LANGUAGES CXX) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(CMAKE_AUTOUIC ON) set(CMAKE_AUTOMOC ON) set(CMAKE_AUTORCC ON) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(PROJECT_DIR ${CMAKE_CURRENT_SOURCE_DIR}) set(PROJECT "FOO") set(QML_IMPORT_PATH "C:/Qt/5.15.2/msvc2019_64/qml") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Qt5Widgets_EXECUTABLE_COMPILE_FLAGS}") set(CMAKE_PREFIX_PATH "C:/Qt/5.15.2/msvc2019_64/lib/cmake") set(RESOURCES Resources.qrc ) set(qml_resource_files "map.qml" ) find_package(Qt5 COMPONENTS Core Gui Qml Quick Widgets QuickWidgets Network Positioning Location OpenGL Sql REQUIRED) find_package(QT NAMES Qt6 Qt5 COMPONENTS Widgets REQUIRED) file(GLOB PROJECT_SOURCES "main.cpp" "Qml/*.qml" "*.qrc" "MainWindow.h" "MainWindow.cpp" "MainWindow.ui" ) qt5_add_resources(QT_RESOURCES Resource.qrc) target_link_libraries(Foo PRIVATE Qt5::Core Qt5::Quick Qt5::QuickWidgets Qt5::Gui Qt5::Qml Qt5::Widgets Qt5::Positioning Qt5::Network Qt5::Location Qt5::Sql Qt5::OpenGL ) ... ...
My MainWindow.cpp is
Foo::Foo(QWidget *parent) : Foo(parent) , ui(new Ui::Foo) { ui->setupUi(this); QWidget* mapWidget = ui->centralwidget->findChild<QWidget*>("mapWidget"); QQmlEngine* engine = new QQmlEngine(this); engine->addImportPath("C:/Qt/5.15.2/msvc2019_64/qml"); engine->addImportPath("C:/Qt/5.15.2/msvc2019_64/plugins"); mapView = new QQuickWidget(engine, mapWidget); QQmlContext* context = engine->rootContext(); mapView->setSource(QUrl(QStringLiteral("qrc:/Qml/map.qml")));
And for the last, my map.qml is
import QtQuick 2.15 import QtPositioning 5.15 import QtLocation 5.15 import QtQuick.Controls 2.15 Item { id: mapItem Map { id: mapControl plugin: Plugin { id: mapPlugin name: "mapboxgl" PluginParameter { name: "mapboxgl.access_token" value: <My Token Here> } } activeMapType: mapControl.supportedMapTypes[1] } }
Screen is just white and showing nothing but the output is below
16:03:04: Starting <elision>\build.x64\Debug\Foo.exe...
1 , "The geoservices provider is not supported."
qrc:/Qml/map.qml:18:9: Unable to assign [undefined] to QDeclarativeGeoMapType*Any help please !
-
Hi and welcome to devnet,
Surprisingly, the documentation only mentions MinGW for Windows. Did you try it ?
-
Hi and welcome to devnet,
Surprisingly, the documentation only mentions MinGW for Windows. Did you try it ?
-
Hi and welcome to devnet,
Surprisingly, the documentation only mentions MinGW for Windows. Did you try it ?
Hi @SGaist
Thank you for replying !!
After changing MSVC to MinGW and CMakeLists.txt,
I got following log message.
How can I solve it ??
10:03:59: Starting C:\Users\user\Desktop\untitled\build\Desktop_Qt_5_15_2_MinGW_64_bit-Debug\untitled.exe...
QObject::connect(QQuickWindow, QDeclarativeGeoMap): invalid nullptr parameter
10:04:01: C:\Users\user\Desktop\untitled\build\Desktop_Qt_5_15_2_MinGW_64_bit-Debug\untitled.exe exited with code 0 -
MinGW perfectly works now !!!!
If anyone moving MSVC->MinGW you should check project cmake's "Current Configuration". which would be set to C:/Qt/5.15.2/msvc2019_64/ ~~~.
It must be changed to C:/Qt/5.15.2/mingw81_64/~~~
And in QML file, Map field should have "achors.fill: parent"
All fixed well. super thanks to @SGaist you saved my life
-