【问题标题】:Qt Maps (QML) application window is blankQt Maps (QML) 应用程序窗口为空白
【发布时间】:2015-06-02 19:32:43
【问题描述】:

这是我正在尝试制作的 Qt Maps 应用程序的代码。 http://pastebin.com/PNcYivM9 - main.qml

我在 Ubuntu 14.04 上使用 Qt Creator。 当我编译并运行代码时,应用程序窗口是空白的。

除了添加 Qt Location 导入之外,我没有编辑 main.ui.qml。

我还在 .pro 文件中添加了 location 关键字 任何帮助将不胜感激,因为我在地图上真的找不到任何教程。

编辑: 这是代码

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
//    }
    }




}

【问题讨论】:

  • 在我的代码中,我将 center 属性保留在 cmets 中,因为它显示错误“无效的分组属性访问”
  • 我们大多数人永远不会看到您的代码,因为它位于外部网站上,而不是包含在您的帖子中。
  • 然后我会包含它。我认为这样会更容易。

标签: c++ qt qml


【解决方案1】:

您的Map 没有设置尺寸,因此默认宽度和高度为零。要查看这种情况,请将以下内容添加到您的 Map 组件中:

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

这将打印出来:

尺寸:0 0

因此,您要么需要将尺寸设置为非零值,要么使用anchor 属性将尺寸附加到父锚点。

【讨论】:

  • 插件的使用方式是否正确?我没有为插件安装任何东西,我只是编写了代码。我现在尝试添加锚点。
  • @user3927312 我相信是的。
  • 谢谢!那行得通!不过,我现在还有另一个问题。就像我上面提到的,如果我删除“中心”属性上的 cmets,它会说无效的分组属性访问。对此有什么想法吗?
  • 听起来像是一个单独的问题。
  • 那我把它作为一个发布?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2023-03-27
  • 2022-08-16
  • 1970-01-01
  • 2014-02-19
  • 2015-10-30
  • 1970-01-01
  • 2016-10-10
相关资源
最近更新 更多