View Single Post
Posts: 71 | Thanked: 456 times | Joined on Jan 2017 @ Portugal
#9
Back to your question, Settings belong to Qt.labs.settings wich is not available in Sailfish, so you have to use
ConfigurationGroup, here is a sample program that should work (untested )

Code:
import Nemo.Configuration 1.0

Item {

	Rectangle {
		id: rect
		anchors.fill: parent
		color: '#000000'

		MouseArea {
			anchors.fill: parent
			onClicked: rect.color = Qt.hsla(Math.random(), 0.5, 0.5, 1.0);
		}
	}
	
	
	ConfigurationGroup {
        id: settings
        path: "/apps/harbour-yourApp"
    }
	
	Component.onCompleted: {
		rect.color = settings.value("rectColor", "#000000")
	}
	
	Component.onDestruction: {
		settings.setValue("rectColor", rect.color)
	}
}
From the docs:
variant value(string key, variant defaultValue, int typeHint)
Returns the value of key as a variant. If key does not exist defaultValue will be returned.
The line
rect.color = settings.value("rectColor", "#000000")
tries to load the value of rectColor, if that doenst exist (at the first time it wont) it will load the default value "#000000". The rest is pretty straightforward, on destruction the last rectangle color will be saved in rectColor string. While reading the docs is important, I have to agree that this particular documentation about ConfigurationGroup is very poor.
Feel free to ask any more questions if something is unclear to you, and keep on coding

Cheers
 

The Following 4 Users Say Thank You to john_god For This Useful Post: