Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Database Error
Qt 6.11 is out! See what's new in the release blog

Database Error

Scheduled Pinned Locked Moved QML and Qt Quick
1 Posts 1 Posters 1.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    theCrazyCrap
    wrote on last edited by
    #1

    HI, I'm creating a RPG game on qt quick with a save game feature. In order for me to do that is to have a database to store in which level the player have finished. But when I am trying to run the program. It has an error "cannot find database" or reference error. Please help me and thank you in advance! Here is my code.

    Database.js

    @function getGameBase(){
    return openDatabaseSync("gameBase", "1.0", "StorageDatabase", 50);
    }

    function initialize() {
    var db = getGamebase();
    db.transaction(
    function(tx) {
    tx.executeSql('CREATE TABLE IF NOT EXISTS game(gameNum NUMBER UNIQUE,money NUMBER,str NUMBER,int NUMBER,def NUMBER,level NUMBER)');

            //initialize start up value
                    for(i=0; i <=3; i++ )
                    {
                        tx.executeSql('INSERT INTO game VALUES (?, 100,5,3,5,0)', [i])
                    }
    
                });
    

    }

    function getMoney(gameIter){
    var db = getGameBase();

    db.transaction(function(tx){
                       var rs = tx.executeSql('SELECT money FROM game WHERE gameNum=?;', [gameIter])}
                       )
    return rs
    

    }

    function getLevel(gameIter){
    var db = getGameBase();

    db.transaction(function(tx){
                       var rs = tx.executeSql('SELECT level FROM game WHERE gameNum=?;', [gameIter])}
                       )
    return rs
    

    }

    @

    Main Qml
    @import QtQuick 1.1
    import com.nokia.symbian 1.1
    import "database.js" as Storage

    Page{
    id:mainPage

    property int gameMoney
    property int tempCon
    property int tempLvl
    property int resCont
    
    
    function retMoney(iter)
    {
        tempCon = Storage.getMoney
        return tempCon
    }
    
    function retLevel(a)
    {
        tempLvl = Storage.getLevel(a)
        return tempLvl
    }
    
    Image
    {   id: background
        width:parent.width ; height: parent.height
        source:"image/woodBg.jpg"
    
        Row
        {   x:35 ;y:20
    
            Image
            {   id:menu1
                source:"image/mainTile.png"
    
                MouseArea{
                    id:msArea1
                    anchors.fill: parent
                }
    
                Text
                {id:money1
                 x:20 ; y:40}
    
                Text
                {id:lvl1;
                 x:20 ; y:80}
    
                Button
                {
                    id:mbt1
                    x:40; y:250
                    text:"New Game"
                }
            }
    
            Image
            {   id:menu2
                source:"image/mainTile.png"
    
                MouseArea{
                    id:msArea2
    
                }
    
                Text
                {id:money2;text:"Money: "
                    x:20 ; y:40}
    
                Text
                {id:lvl2; text:"Level: "
                 x:20 ; y:80}
    
                Button
                {
                    id:mbt2
                    x:40; y:250
                    text:"New Game"
                }
            }
    
            Image
            {   id:menu3
                source:"image/mainTile.png"
    
                MouseArea{
                    id:msArea3
                }
    
                Text
                {id:money3;
    
                 text:"Money: "
                    x:20 ; y:40}
    
                Text
                {id:lvl3; text:"Level: "
                 x:20 ; y:80}
    
                Button
                {
                    id:mbt3
                    x:40; y:250
                    text:"New Game"
    
                }
            }
    
            Component.onCompleted: {
                Storage.getGameBase();
                Storage.initialize();
                money1.text = "Money: \n" + Storage.getMoney('1')
        }
    }
    

    }
    }

    @

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved