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. Set path of PolyLine from the c++ file
Forum Updated to NodeBB v4.3 + New Features

Set path of PolyLine from the c++ file

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
1 Posts 1 Posters 322 Views
  • 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.
  • G Offline
    G Offline
    GGG03
    wrote on last edited by
    #1

    I am trying to change the path from c++, sending the list from the mainwindow. But it isn't working. Any help?
    The error is "QML MapPolyline: Unsupported path type"

    mainwindow.h

    signals:
            void setCenter(QVariant, QVariant);
            void addMarker(QVariant, QVariant);
            void setMarkers(QVariantList);
    

    mainwindow.cpp

    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    
    #include <QQuickItem>
    
    MainWindow::MainWindow(QWidget *parent)
        : QMainWindow(parent)
        , ui(new Ui::MainWindow)
    {
        ui->setupUi(this);
    
        ui->quickWidget->setSource(QUrl(QStringLiteral("qrc:/map.qml")));
        ui->quickWidget->show();
    
        auto obj = ui->quickWidget->rootObject();
        connect(this, SIGNAL(setCenter(QVariant, QVariant)), obj, SLOT(setCenter(QVariant,QVariant)));
        connect(this, SIGNAL(addMarker(QVariant, QVariant)), obj, SLOT(addMarker(QVariant,QVariant)));
        connect(this, SIGNAL(setMarkers(QVariantList)), obj, SLOT(setMarkers(QVariantList)));
    
        emit setCenter(-28, 153.3658);
        emit addMarker(-28, 153.3658);
    
        QVariantList coordinates;
        coordinates.append(-29);
        coordinates.append(153);
        coordinates.append(-27);
        coordinates.append(154);
        emit setMarkers(coordinates);
    }
    
    MainWindow::~MainWindow()
    {
        delete ui;
    }
    

    map.qml

    import QtQuick 2.0
    import QtLocation 5.6
    import QtPositioning 5.6
    
    Rectangle
    {
        id: window
    
        property double oldLat: 27.6585
        property double oldLng: 153.3658
        property var coordinateList: []
    
        property Component comMarker: mapMarker
    
        Plugin
        {
            id: mapPlugin
            name: "osm"
        }
    
        Map
        {
            id: mapView
            anchors.fill: parent
            plugin: mapPlugin
            center: QtPositioning.coordinate(oldLat, oldLng);
            zoomLevel: 3
    
            MapPolyline
            {
                id: coordinatePath
                line.width: 2
                line.color: 'blue'
                smooth: true
                opacity: 0.8
                path: [coordinateList]
            }
        }
    
        Component
        {
            id: mapMarker
            MapQuickItem
            {
                id: markerImg
                anchorPoint.x: image.width/4
                anchorPoint.y: image.height
                coordinate: position
                sourceItem: Image
                {
                    id: image
                    source: "http://maps.gstatic.com/mapfiles/ridefinder-images/mm_20_red.png"
                }
            }
        }
    
        function setMarkers (list)
        {
            coordinateList = list;
        }
    
        function setCenter(lat, lng)
        {
            mapView.pan(oldLat - lat, oldLng - lng)
            oldLat = lat
            oldLng = lng
        }
    
        function addMarker(lat, lng)
        {
            var item = comMarker.createObject(window, {coordinate: QtPositioning.coordinate(lat, lng)})
            mapView.addMapItem(item)
        }
    
    }
    
    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