I have the following simple sqlite db code, written in Qt:
Note: 'windowid' used in code below refers to the root element's id
Rectangle{
id:enterYourName
anchors.centerIn: nameContianer
color: "white"
width:0.395*windowid.width
height:0.227*windowid.height
function getDatabase() {
return LocalStorage.openDatabaseSync("HomeScreen", "1.0", "StorageDatabase", 100000);
}
function typetable() {
var db = getDatabase();
db.transaction(
function(tx) {
tx.executeSql('CREATE TABLE IF NOT EXISTS mycircletype (mytypee REAL)');
});
}
function setType(yvalue) {
var db = getDatabase();
db.transaction(function(tx) {
tx.executeSql('INSERT OR REPLACE INTO mycircletype VALUES (?);', [yvalue]);
}
);
}
function getType() {
var db = getDatabase();
var res="";
db.transaction(function(tx) {
var rs = tx.executeSql('SELECT mytypee FROM mycircletype');
if (rs.rows.length > 0) {
res = rs.rows.item(0).mytypee;
} else {
res = 0.506*windowid.height;
}
})
return res;
}
Component.onCompleted: {
enterYourName.typetable()
}
}
and i have an image that i would like to save its y value, also i have three rectangles, when any of these rectangles is clicked the y value of the image changes to a specific value, i want to save that value & the next time my application start i want that value to be the y value of my image, for illustration here is my code:
// here is the image
Image{
id:tick1
source: "../../pics/tick.png"
width:0.0395*windowid.width
height:0.041*windowid.height
x: 0.4474*windowid.width
y: enterYourName.getType() //here the issue appears
visible: false
}
// here are the 3 rectangles
Rectangle{
id: op2op1
x:windowid.width+10
y:0.324*windowid.height
width:0.170*windowid.width
height:0.130*windowid.height
MouseArea{
anchors.fill: parent
onClicked: {
enterYourName.setType(0.370*windowid.height)
tick1.y = 0.370*windowid.height
tick1.visible = true
}
}
}
Rectangle{
id: op2op2
x:0.350*windowid.width
y:0.364*windowid.height
width:0.170*windowid.width
height:0.130*windowid.height
MouseArea{
anchors.fill: parent
onClicked: {
enterYourName.setType(0.231*windowid.height)
tick1.y = 0.231*windowid.height
tick1.visible = true
}
}
}
Rectangle{
id: op2op3
x:0.350*windowid.width
y:0.364*windowid.height
width:0.170*windowid.width
height:0.130*windowid.height
MouseArea{
anchors.fill: parent
onClicked: {
enterYourName.setType(0.506*windowid.height)
tick1.y = 0.506*windowid.height
tick1.visible = true
}
}
}
unfortunately i'm getting an error saying Unable to assign null to double
, & it's pointing to the y value of the image ( y: enterYourName.getType()), how can this be fixed so that the y value of the image is saved & retrieved without any issues.
Aucun commentaire:
Enregistrer un commentaire