Hi, I’m using VPlay to make an app with database connection. I used Qt LocalStorage to do the login and sign up but after I navigate to my home page i can’t access that data. I also want to store and load media files from file dialogs. Please help. here is my database management code
import Felgo 3.0
import QtQuick 2.7
import QtQuick.Controls 2.0
import QtQuick.Layouts 1.1
import QtQuick.LocalStorage 2.0
import "./backend.js" as BackEnd
App {
id: app
property bool databaseOpen: false
property color popupBackGroundColor: "#b44"
property color popupTextCOlor: "#ffffff"
property var dataBase
// You get free licenseKeys from https://felgo.com/licenseKey
// With a licenseKey you can:
// * Publish your games & apps for the app stores
// * Remove the Felgo Splash Screen or set a custom one (available with the Pro Licenses)
// * Add plugins to monetize, analyze & improve your apps (available with the Pro Licenses)
//licenseKey: "<generate one from https://felgo.com/licenseKey>"
StackView{
id: stackView
focus: true
anchors.fill: parent
}
Component.onCompleted: {
//initial page
stackView.push("RegistrationPage.qml")
dataBase = userDataBase()
console.log(dataBase.version)
}
Dialog {
id: popup
title: "Error!!"
property alias popMessage: message.text
focus: true
positiveActionLabel: "Close"
onAccepted: close()
AppText {
id: message
anchors.centerIn: parent
font.pointSize: dp(25)
color: "red"
}
}
// Popup will be closed automatically in 2 seconds after its opened
property string uname: ""
property string gmail_account: ""
function userDataBase()
{
var db = LocalStorage.openDatabaseSync("UserLoginApp", "1.0", "Login example!", 1000000);
db.transaction(function(tx) {
tx.executeSql('CREATE TABLE IF NOT EXISTS UserDetails(username TEXT, gmailAccount TEXT, programmingLanguage TEXT)');
})
return db;
}
// Register New user
function registerNewUser(uname, gmail_account, programminglanguage)
{
var ret = BackEnd.validateRegisterCredentials(uname, gmail_account)
var message = ""
switch(ret)
{
case 0: message = "Valid details!"
break;
case 1: message = "Missing credentials!"
break;
}
if(0 !== ret)
{
popup.popMessage = message
popup.open()
return
}
dataBase.transaction(function(tx) {
var results = tx.executeSql('SELECT gmailAccount FROM UserDetails WHERE username=?;', uname);
console.log(results.rows.length)
if(results.rows.length !== 0)
{
popup.popMessage = "User already exist!"
popup.open()
return
}
tx.executeSql('INSERT INTO UserDetails VALUES(?, ?, ?)', [ uname, gmail_account, programminglanguage ]);
showUserInfo(uname) // goto user info page
})
}
// Login users
function loginUser(uname, gmail_account)
{
var ret = BackEnd.validateUserCredentials(uname, gmail_account)
var message = ""
if(ret)
{
message = "Missing credentials!"
popup.popMessage = message
popup.open()
return
}
dataBase.transaction(function(tx) {
var results = tx.executeSql('SELECT gmailAccount FROM UserDetails WHERE username=?;', uname);
if(results.rows.length === 0)
{
message = "User not registered!"
popup.popMessage = message
popup.open()
}
else
{
console.log("Login Success!")
showDashboardPage(uname,gmail_account)
}
})
}
function showDashboardPage(uname,gmail_account){
stackView.replace("Dashboard.qml", {"userName": uname, "gmailAccount": gmail_account})
}
onInitTheme: {
if(system.desktopPlatform)
Theme.platform = "android"
}
}
And the homepage where I call the username and gmail account
headerView: Item {
width: parent.width
height: dp(120)
property string userName: userName
property string gmailAccount: gmailAccount
RoundedImage {
id: bgImage
radius: 0
anchors.fill: parent
fillMode: Image.PreserveAspectCrop
source: image
Column {
anchors.centerIn: parent
width: parent.width
Item { height: dp(5); width: parent.width } // spacer
AppText {
width: parent.width
horizontalAlignment: Text.Center
color: "white"
text: "Name: " + userName
font.pixelSize: sp(14)
font.bold: true
font.family: Theme.boldFont.name
}
AppText {
width: parent.width
text: "Name: " + gmailAccount
horizontalAlignment: Text.Center
color: "white"
font.pixelSize: sp(13)
}
}
}
}
For the audio files. I just need to know how to save and load from path. Like a ringing tone or a profile picture. If there is a way to save filedialog data into local storage, Please let me know. Thanks in advance