Reply
Thread Tools
Markkyboy's Avatar
Posts: 433 | Thanked: 727 times | Joined on Oct 2012 @ Costa Blanca, Espaņa
#1
Hi,

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?

Code:
    import com.jolla.settings 1.0

        Rectangle {
            id: rect
            anchors.fill: parent
            color: '#000000'
            Settings { //hash this out and the code works but won't save last color created.
                id: settings
                property alias color: rect.color
            }
            MouseArea {
                anchors.fill: parent
                onClicked: rect.color = Qt.hsla(Math.random(), 0.5, 0.5, 1.0);
            }
        }
    }
Thanks,
__________________
..oO(Don't just sit there standing around, pick up a shovel and sweep up!)Oo..
 

The Following 5 Users Say Thank You to Markkyboy For This Useful Post:
velox's Avatar
Posts: 394 | Thanked: 1,341 times | Joined on Dec 2009
#2
Hi,
have a look at https://sailfishos.org/develop/docs/...ionvalue.html/

cheers
__________________
slumber: sensors enabled sleep timer for SFOS (translations/input/… appreciated if you've got some spare time)
talefish: directory based audiobook player for SFOS
nofono: ofono restart for SFOS
___
list of i486/noarch packages on openrepos (jolla tablet)
 

The Following 7 Users Say Thank You to velox For This Useful Post:
Ancelad's Avatar
Posts: 1,552 | Thanked: 3,108 times | Joined on Jun 2012 @ Russia, 96
#3
Explore Lockscreen Analog Clock settings page.
 

The Following 7 Users Say Thank You to Ancelad For This Useful Post:
coderus's Avatar
Posts: 6,436 | Thanked: 12,699 times | Joined on Nov 2011 @ Ängelholm, Sweden
#4
Explore documentation and stop doing random copy-paste activities without understanding how it works.
__________________
Telegram | Openrepos | GitHub | Revolut donations
 

The Following User Says Thank You to coderus For This Useful Post:
Markkyboy's Avatar
Posts: 433 | Thanked: 727 times | Joined on Oct 2012 @ Costa Blanca, Espaņa
#5
Originally Posted by coderus View Post
Explore documentation and stop doing random copy-paste activities without understanding how it works.
Stop, why?, who are you to tell me to stop?, how about you stop with your narky comments, there are no teachers for this kind of thing and why shouldn't I ask?, this is how we learn.

You don't like my questions?, don't fkin answer them, simples!
__________________
..oO(Don't just sit there standing around, pick up a shovel and sweep up!)Oo..
 

The Following 4 Users Say Thank You to Markkyboy For This Useful Post:
Markkyboy's Avatar
Posts: 433 | Thanked: 727 times | Joined on Oct 2012 @ Costa Blanca, Espaņa
#6
Originally Posted by velox View Post
Hi,
have a look at https://sailfishos.org/develop/docs/...ionvalue.html/

cheers
Thanks velox, I see very little on that page to help me understand how to use it. No examples, not even a slice of code to look at.

Edit: what I mean to say is, I was hoping for more information. However, it's unreal for me, that I didn't connect the dots, just a few days ago Ancelad showed me about ConfigurationGroup, so I do have a starting place. Thanks for your input.
__________________
..oO(Don't just sit there standing around, pick up a shovel and sweep up!)Oo..

Last edited by Markkyboy; 2018-08-31 at 21:39.
 

The Following 3 Users Say Thank You to Markkyboy For This Useful Post:
Dave999's Avatar
Posts: 7,074 | Thanked: 9,069 times | Joined on Oct 2009 @ Moon! It's not the East or the West side... it's the Dark Side
#7
Originally Posted by coderus View Post
Explore documentation and stop doing random copy-paste activities without understanding how it works.
Imagine if humans would stop doing things they didn’t understand.
Feel free to take it as an advice or...

What documentation would that be?
__________________
Do something for the climate today! Anything!

I don't trust poeple without a Nokia n900...

Last edited by Dave999; 2018-08-31 at 20:21.
 

The Following 3 Users Say Thank You to Dave999 For This Useful Post:
Markkyboy's Avatar
Posts: 433 | Thanked: 727 times | Joined on Oct 2012 @ Costa Blanca, Espaņa
#8
Originally Posted by Dave999 View Post
Imagine if humans would stop doing things they didn’t understand.
Feel free to take it as an advice or...

What documentation would that be?
Lol, thanks Dave......I have a habit of taking things the wrong way, just as dear coderus can be, well, a bit short at times.

The documentation for sailfish doesn't give much away, fine for those who grew up with coding, got shown, learned from their dad/brother, did it at school, they already have some roots in the subject, I don't have that under my belt.

The documentation as pointed out by velox, I have already looked, it really gives very little information, there is not even an example, which leads me to believe, if you are developing for Sailfish, it is assumed you already know your way round coding. Recently, Ancelad showed me a usage for ConfigurationGroup, okay cool, now I have to learn about dconf and keys, I know how to read/list/search dconf, I even learned how to remove/reset a dconf value but as yet, I'm not quite understanding about 'path' and setting its values, sometimes I need to be shown.

My question about the color changing rectangle was an exercise in understanding Settings, I found it easier work with a rectangle, mouse area and a bit about color, familiar ground, easy stuff. Now I have to connect ConfigGroup to my actual code, which is about changing windspeed units, from default m/s to mph/kmh/kts by tapping on the windspeed output in sailfish weather.

I lack discipline, especially when info appears to be thin on the ground...but the main thing is, I'm keen to learn about it all and I'm not going to stop doing what I'm doing despite what others think, as for reading documentation, I'm always looking at that or my device before asking questions. After all, isn't this what TMO is for?
__________________
..oO(Don't just sit there standing around, pick up a shovel and sweep up!)Oo..
 

The Following 3 Users Say Thank You to Markkyboy For This Useful 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:
Markkyboy's Avatar
Posts: 433 | Thanked: 727 times | Joined on Oct 2012 @ Costa Blanca, Espaņa
#10
Originally Posted by john_god View Post
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
Thank you john_god, just the type of explanation I needed and it with very little tweaking, the code works!

user 'velox' was also on the money, I just needed to see a working example with sailfish to get an understanding of how it works, also Ancelad guided me along a similar path recently using ConfigGroup, but for some reason, I find your example easier to follow/understand and above all, I get the outcome I wanted.

I realised after searching my device, the qt.labs.settings does not exist in sailfish, so one of or at least, my main question should have been "what is the equivalent to qt.labs.settings?".

With minor tweaks, the code looks like this;

Code:
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 last colour I selected does indeed reappear after closing and opening the application, perfect, just what I was after, kudos john_god!
__________________
..oO(Don't just sit there standing around, pick up a shovel and sweep up!)Oo..
 

The Following 5 Users Say Thank You to Markkyboy For This Useful Post:
Reply

Thread Tools

 
Forum Jump


All times are GMT. The time now is 23:58.