为什么我收到错误“无法分配给不存在的属性”头部?

我实际上是在Trusty上,我想尝试新的“head”属性,它附带了Ubuntu SDK的API 14.10。

当我启动qmlscene来测试我的应用程序时,我收到此错误:

Cannot assign to non-existent property "head" 

我在qml文件中导入了这个:

 import QtQuick 2.2 import Ubuntu.Components 1.1 

谢谢你的帮助。

编辑:代码示例

 import Ubuntu.Components 1.1 import QtQuick 2.2 MainView { width: units.gu(50) height: units.gu(80) useDeprecatedToolbar: false Page { id: page title: "Sections" head { sections { model: ["one", "two", "three"] } } Label { anchors.centerIn: parent text: "Section " + page.head.sections.selectedIndex } } } 

这是因为您运行的是Ubuntu SDK的过时版本。 即使您已添加SDK PPA,Ubuntu SDK也不再在Ubuntu 14.04(Trusty)上更新。 这是因为Ubuntu SDK需要Qt 5.3,它仅在Ubuntu 14.10中可用。

你可以解决这个问题,

  • 使用仿真器测试您的应用程序。 所以你在Trusty上编码,但是在模拟器中运行它以查看它是否按预期工作。 您可以在此处找到有关入门模拟器的更多信息。
  • 升级到14.10以便能够在桌面上测试和运行应用程序
  • 使用Utopic VirtualBox VM