The Following 5 Users Say Thank You to Markkyboy For This Useful Post: | ||
|
2018-08-31
, 13:24
|
|
Posts: 394 |
Thanked: 1,341 times |
Joined on Dec 2009
|
#2
|
The Following 7 Users Say Thank You to velox For This Useful Post: | ||
|
2018-08-31
, 13:26
|
|
Posts: 1,552 |
Thanked: 3,108 times |
Joined on Jun 2012
@ Russia, 96
|
#3
|
The Following 7 Users Say Thank You to Ancelad For This Useful Post: | ||
|
2018-08-31
, 18:51
|
|
Posts: 6,436 |
Thanked: 12,701 times |
Joined on Nov 2011
@ Ängelholm, Sweden
|
#4
|
The Following User Says Thank You to coderus For This Useful Post: | ||
|
2018-08-31
, 19:19
|
|
Posts: 433 |
Thanked: 727 times |
Joined on Oct 2012
@ Costa Blanca, Espaņa
|
#5
|
Explore documentation and stop doing random copy-paste activities without understanding how it works.
The Following 4 Users Say Thank You to Markkyboy For This Useful Post: | ||
|
2018-08-31
, 19:26
|
|
Posts: 433 |
Thanked: 727 times |
Joined on Oct 2012
@ Costa Blanca, Espaņa
|
#6
|
Hi,
have a look at https://sailfishos.org/develop/docs/...ionvalue.html/
cheers
The Following 3 Users Say Thank You to Markkyboy For This Useful Post: | ||
|
2018-08-31
, 20:14
|
|
Posts: 7,075 |
Thanked: 9,073 times |
Joined on Oct 2009
@ Moon! It's not the East or the West side... it's the Dark Side
|
#7
|
Explore documentation and stop doing random copy-paste activities without understanding how it works.
The Following 3 Users Say Thank You to Dave999 For This Useful Post: | ||
|
2018-08-31
, 22:38
|
|
Posts: 433 |
Thanked: 727 times |
Joined on Oct 2012
@ Costa Blanca, Espaņa
|
#8
|
Imagine if humans would stop doing things they didnt understand.
Feel free to take it as an advice or...
What documentation would that be?
|
2018-09-01
, 17:39
|
Posts: 71 |
Thanked: 456 times |
Joined on Jan 2017
@ Portugal
|
#9
|
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) } }
The Following 4 Users Say Thank You to john_god For This Useful Post: | ||
|
2018-09-02
, 08:38
|
|
Posts: 433 |
Thanked: 727 times |
Joined on Oct 2012
@ Costa Blanca, Espaņa
|
#10
|
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 )
From the docs: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) } }
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
import QtQuick 2.0 import Sailfish.Silica 1.0 import org.nemomobile.configuration 1.0 Page { 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) }
The Following 5 Users Say Thank You to Markkyboy For This Useful Post: | ||
I have a Page, on that page is a rectangle, I can click on the rectangle and it changes colour, I'd like the last colour picked to remain when I reopen the app again. I thought I could do this with settings, but it doesn't work.
It seems as soon as I introduce 'settings' into the code that the app doesn't open. I thought maybe to include 'import com.jolla.settings 1.0' but that doesn't help either, what am I doing wrong?
..oO(Don't just sit there standing around, pick up a shovel and sweep up!)Oo..