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. I want to see map with cmake, qml. But it's not working
Forum Updated to NodeBB v4.3 + New Features

I want to see map with cmake, qml. But it's not working

Scheduled Pinned Locked Moved Solved QML and Qt Quick
6 Posts 2 Posters 552 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
    Diaxion
    wrote on last edited by
    #1

    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 !

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

      Hi and welcome to devnet,

      Surprisingly, the documentation only mentions MinGW for Windows. Did you try it ?

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

      D 2 Replies Last reply
      0
      • SGaistS SGaist

        Hi and welcome to devnet,

        Surprisingly, the documentation only mentions MinGW for Windows. Did you try it ?

        D Offline
        D Offline
        Diaxion
        wrote on last edited by
        #3
        This post is deleted!
        D 1 Reply Last reply
        0
        • D Diaxion

          This post is deleted!

          D Offline
          D Offline
          Diaxion
          wrote on last edited by
          #4
          This post is deleted!
          1 Reply Last reply
          0
          • SGaistS SGaist

            Hi and welcome to devnet,

            Surprisingly, the documentation only mentions MinGW for Windows. Did you try it ?

            D Offline
            D Offline
            Diaxion
            wrote on last edited by
            #5

            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

            1 Reply Last reply
            0
            • D Offline
              D Offline
              Diaxion
              wrote on last edited by
              #6

              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

              1 Reply Last reply
              1
              • D Diaxion has marked this topic as solved on

              • Login

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