Planned maintenance has been done but it did not solve the problem. So work will continue on this and a new time for trying updates will be announced asap.

App runs on both Android and desktop, but something is not working on Android...



  • Hey!

    I have a program where I want to enter a map. I've used the example app called "Map Viewer" from Qt to create the map.
    If I run the application on my desktop, everything is working as it should. I mean, every button, slider and mouse event it noticed and acted upon.

    When I run my app on Android (Nexus 7 tablet) the mouse event, buttons or slider doesnt react to anything.

    Here is my code for the MapComponent:
    @

    import QtQuick 2.7
    import QtQuick.Controls 1.4
    import QtLocation 5.6
    import QtPositioning 5.5
    import "../js/helper.js" as Helper

    Map {

    property variant scaleLengths: [5, 10, 20, 50, 100, 200, 500, 1000, 2000, 5000, 10000, 20000, 50000, 100000, 200000, 500000, 1000000, 2000000]
    property int lastX : -1
    property int lastY : -1
    property int pressX : -1
    property int pressY : -1
    
    
    
    id: map
    copyrightsVisible: false
    zoomLevel: (maximumZoomLevel-minimumZoomLevel)/2
    plugin: Plugin {name: "osm"}
    
    //The center
    center {
        // The Qt Company in Oslo
        latitude: xxx
        longitude: xxx
    }
    
    //Center image
    MapQuickItem {
        id: centerImage
        sourceItem: Image {
            id: image
            source: "qrc:/images/triangle.svg"
            //TODO: replace image
        }
        coordinate: map.center
        opacity: 1.0
    }
    
    
    //! [mapnavigation]
    // Enable pan, flick, and pinch gestures to zoom in and out
    gesture.acceptedGestures: MapGestureArea.PanGesture | MapGestureArea.FlickGesture | MapGestureArea.PinchGesture
    gesture.flickDeceleration: 3000
    gesture.enabled: true
    
    //! [mapnavigation]
    
    onCenterChanged:{
        scaleTimer.restart()
    }
    
    onZoomLevelChanged:{
        scaleTimer.restart()
        map.forceActiveFocus()
    }
    
    onWidthChanged:{
        scaleTimer.restart()
    }
    
    onHeightChanged:{
        scaleTimer.restart()
    }
    
    Component.onCompleted: {
        //Do anything here?
    }
    
    //PD Location
    MapQuickItem {
        id: poiPD
        sourceItem: Rectangle { width: 14; height: 14; color: "#e41e25"; border.width: 2; border.color: "white"; smooth: true; radius: 7 }
        coordinate {
            latitude: xxx
            longitude: xxx        }
        opacity: 1.0
        anchorPoint: Qt.point(sourceItem.width/2, sourceItem.height/2)
    }
    
    
    //Scaler item
    Item {
        id: scale
        visible: scaleText.text != "0 m"
        anchors.bottom: parent.bottom;
        anchors.right: parent.right
        anchors.margins: 20
        height: scaleText.height * 2
        width: scaleImage.width
    
        Image {
            id: scaleImageLeft
            source: "qrc:/images/MapResources/scale_end.png"
            anchors.bottom: parent.bottom
            anchors.right: scaleImage.left
        }
        Image {
            id: scaleImage
            source: "qrc:/images/MapResources/scale.png"
            anchors.bottom: parent.bottom
            anchors.right: scaleImageRight.left
        }
        Image {
            id: scaleImageRight
            source: "qrc:/images/MapResources/scale_end.png"
            anchors.bottom: parent.bottom
            anchors.right: parent.right
        }
        Label {
            id: scaleText
            color: "#004EAE"
            anchors.centerIn: parent
            text: "0 m"
        }
        Component.onCompleted: {
            map.calculateScale();
        }
    }
    
    
    
    //To update the values of the scaler at all times
    Timer {
        id: scaleTimer
        interval: 100
        running: false
        repeat: false
        onTriggered: {
            map.calculateScale()
        }
    }
    
    MouseArea {
            id: mouseArea
            z: map.z + 3
            property variant lastCoordinate
            anchors.fill: parent
    
            onPressed : {
                map.lastX = mouse.x
                map.lastY = mouse.y
                map.pressX = mouse.x
                map.pressY = mouse.y
                lastCoordinate = map.toCoordinate(Qt.point(mouse.x, mouse.y))
                console.log("Mouse pressed")
            }
    
            onPositionChanged: {
                map.lastX = mouse.x
                map.lastY = mouse.y
    
                console.log("Mouse changed")
            }
    
            onDoubleClicked: {
                var mouseGeoPos = map.toCoordinate(Qt.point(mouse.x, mouse.y));
                var preZoomPoint = map.fromCoordinate(mouseGeoPos, false);
    
    
                map.zoomLevel++;
    
                var postZoomPoint = map.fromCoordinate(mouseGeoPos, false);
                var dx = postZoomPoint.x - preZoomPoint.x;
                var dy = postZoomPoint.y - preZoomPoint.y;
    
                var mapCenterPoint = Qt.point(map.width / 2.0 + dx, map.height / 2.0 + dy);
                map.center = map.toCoordinate(mapCenterPoint);
    
                lastX = -1;
                lastY = -1;
    
                console.log("Mouse double clicked")
            }
        }
    
    //Slider to zoom
    Slider {
        id: zoomSlider;
        z: map.z + 3
        minimumValue: map.minimumZoomLevel;
        maximumValue: map.maximumZoomLevel;
        anchors.margins: 10
        anchors.bottom: scale.top
        anchors.top: menuButton.bottom
        anchors.right: parent.right
        orientation : Qt.Vertical
        value: map.zoomLevel
    
        onValueChanged: {
            map.zoomLevel = value
        }
    }
    
    //Menu button
    RectangularButton{
        id: menuButton
        z: map.z + 3
        text: "Menu"
        anchors.top: parent.top
        anchors.right: parent.right
        anchors.margins: 10
    
    
        onClicked: {
            console.log("Open menu for map")
        }
    }
    
    
    //Calculates the scale text and image
    function calculateScale()
    {
        var coord1, coord2, dist, text, f
        f = 0
        coord1 = map.toCoordinate(Qt.point(0,scale.y))
        coord2 = map.toCoordinate(Qt.point(0+scaleImage.sourceSize.width,scale.y))
        dist = Math.round(coord1.distanceTo(coord2))
    
        if (dist === 0) {
            // not visible
        } else {
            for (var i = 0; i < scaleLengths.length-1; i++) {
                if (dist < (scaleLengths[i] + scaleLengths[i+1]) / 2 ) {
                    f = scaleLengths[i] / dist
                    dist = scaleLengths[i]
                    break;
                }
            }
            if (f === 0) {
                f = dist / scaleLengths[i]
                dist = scaleLengths[i]
            }
        }
    
        text = Helper.formatDistance(dist)
        scaleImage.width = (scaleImage.sourceSize.width * f) - 2 * scaleImageLeft.sourceSize.width
        scaleText.text = text
    }
    

    }

    @

    Any clarification?