简体   繁体   English

Qt Maps(QML)应用程序窗口为空白

[英]Qt Maps (QML) application window is blank

This is my code for a Qt Maps application I'm trying to make. 这是我要制作的Qt Maps应用程序的代码。 http://pastebin.com/PNcYivM9 - main.qml http://pastebin.com/PNcYivM9-main.qml

I'm using Qt Creator on Ubuntu 14.04. 我在Ubuntu 14.04上使用Qt Creator。 When I do compile and run the code the application window is blank. 当我编译并运行代码时,应用程序窗口为空白。

I haven't edited the main.ui.qml apart from adding the Qt Location import. 除了添加Qt Location导入之外,我没有编辑main.ui.qml。

I've also added the location keyword in the .pro file Any help would be appreciated since I can't really find any tutorials on maps. 我还在.pro文件中添加了location关键字。由于我在地图上找不到任何教程,因此将不胜感激。

EDIT: Here's the code 编辑:这是代码

import QtQuick 2.4
import QtQuick.Controls 1.3
import QtQuick.Window 2.2
import QtQuick.Dialogs 1.2
import QtLocation 5.4

ApplicationWindow {
    title: qsTr("Hello World")
    width: 640
    height: 480
    visible: true


    Plugin{
        id: osmplugin
        name:"osm"
    }

    Map {
        plugin: osmplugin

        id: map
        zoomLevel: (maximumZoomLevel - minimumZoomLevel)/2


//        center {
//            latitude: -27.5796
//            longitude: 153.1003
//        }

        // Enable pinch gestures to zoom in and out
        gesture.flickDeceleration: 3000
        gesture.enabled: true

//    center {
//        latitude: -27.5796
//        longitude: 153.1003
//    }
    }




}

Your Map has no dimensions set, so it's going to default to a width and height of zero. 您的Map未设置尺寸,因此默认将其宽度和高度设置为零。 To see that this is the case, add the following to your Map component: 若要查看情况,请在Map组件中添加以下内容:

Component.onCompleted: {
    console.log("Dimensions: ", width, height)
}

This will print out: 这将打印出:

Dimensions: 0 0 尺寸:0 0

So you either need to set the dimensions to a value other than zero, or use the anchor property to attach the dimensions to the parent's anchors. 因此,您需要将尺寸设置为非零的值,或者使用anchor属性将尺寸附加到父级的锚。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM