Here is the updated code for the full tutorial that now works on my laptop. The changes are:
- Introduce Page as the only component inside MainView
- Set the title of the page to i18n.tr("Currency Converter")
- Remove the Label component completely
- Move all other components inside Page (except for the convert function)
- Make sure the convert function is defined outside the Page component
- Remove topMargin: title.height in the Column component
Here is the updated code for the full tutorial that now works on my laptop. The changes are:
- Introduce Page as the only component inside MainView
- Set the title of the page to i18n.tr("Currency Converter")
- Remove the Label component completely
- Move all other components inside Page (except for the convert function)
- Make sure the convert function is defined outside the Page component
- Remove topMargin: title.height in the Column component
import QtQuick 2.0 XmlListModel 2.0 Components. ListItems 0.1 Components. Popups 0.1
import QtQuick.
import Ubuntu.Components 0.1
import Ubuntu.
import Ubuntu.
MainView { Name: "CurrencyConverter"
objectName: "mainView"
application
id: root
width: units.gu(60)
height: units.gu(80)
property real margins: units.gu(2)
property real buttonWidth: units.gu(9)
Page {
title: i18n.tr("Currency Converter")
ListModel {
ListElemen t {
currency: "EUR"
rate: 1.0
id: currencies
}
}
}
}
id: ratesFetcher
source: "http://
query: "/gesmes:
if (status === XmlListModel.Ready) {
}
}
XmlRole { name: "currency"; query: "@currency/ string( )" }
XmlRole { name: "rate"; query: "@rate/string()" }
}
}
Component {
Column {
anchors {
top: parent.top
left: parent.left
right: parent.right
}
height: pageLayout.height
Header {
id: header
text: i18n.tr("Select currency")
}
ListView {
clip: true
width: parent.width
height: parent.height - header.height
model: currencies
delegate: Standard {
text: currency
onClicked: {
caller. currencyIndex = index
caller. input.update( )
hide( )
}
}
}
id: currencySelector
Popover {
}
}
}
Column {
id: pageLayout
anchors {
fill: parent
margins: root.margins
spacing: units.gu(1)
}
Row {
spacing: units.gu(1)
}
}
}
Row {
spacing: units.gu(1)
Button {
id: selectorTo
property int currencyIndex: 1
property TextField input: inputTo
text: currencies. getCurrency( currencyIndex)
onClicked : PopupUtils. open(currencySe lector, selectorTo)
}
}
}
Button {
text: i18n.tr("Clear")
width: units.gu(12)
onClicked: {
inputTo. text = '0.0';
inputFrom .text = '0.0';
}
}
}
}
function convert(from, fromRateIndex, toRateIndex) { getRate( fromRateIndex) ; getRate( toRateIndex) * (parseFloat(from) / fromRate);
var fromRate = currencies.
if (from.length <= 0 || fromRate <= 0.0)
return "";
return currencies.
}
}