Using SQLite in QML (Can read, but can't write)



  • i am creating an application that needs to save scores. I already connected the database to the application. I can read the contents of the database! I can also update and insert values in the database! THE PROBLEM is when i close my application and run it again ALL the INSERTED values and UPDATED values are RESET and as if the DATABASE was not been UPDATED! HELPPP THANKS!!

    main.cpp:
    @#include <QtGui/QApplication>
    #include "qmlapplicationviewer.h"
    #include <QDeclarativeEngine>
    #include <QString>
    #include <QDebug>
    #include <QDir>

    Q_DECL_EXPORT int main(int argc, char *argv[])
    {
    QScopedPointer<QApplication> app(createApplication(argc, argv));
    QScopedPointer<QmlApplicationViewer> viewer(QmlApplicationViewer::create());

    QDeclarativeEngine engine;
    QString customPath = "qml/Storage";
    
    QDir dir;
        if(dir.mkpath(QString(customPath))){
            qDebug() << "Default path >> "+engine.offlineStoragePath();
            engine.setOfflineStoragePath(QString(customPath));
            qDebug() << "New path >> "+engine.offlineStoragePath();
        }
    
    viewer->engine()->setOfflineStoragePath(QString(customPath));
    viewer->setOrientation(QmlApplicationViewer::ScreenOrientationAuto);
    viewer->setMainQmlFile&#40;QLatin1String("qml/untitled/main.qml"&#41;&#41;;
    viewer->showExpanded(&#41;;
    
    return app->exec&#40;&#41;;
    

    }
    @

    main.qml
    @import QtQuick 1.0

    Rectangle {
    id: rectangle1
    color: "#ffffff"
    width: 200
    height: 100

    Text {
        id: textArea
        text: "?"
        anchors.horizontalCenter: parent.horizontalCenter
        Component.onCompleted: findScores(&#41;
    }
    
    function findScores(&#41; {
        var db = openDatabaseSync("appScores", "1.0", "Scores", 1000000);
        db.transaction(
                    function(tx) {
                        tx.executeSql('UPDATE scoresRecords SET scoreHour=10, scoreMinute=10 WHERE mapNumber=3 AND mapDifficulty="Hard"');
    
                        var rs = tx.executeSql('SELECT * FROM scoresRecords');
    
                        var r = ""
                        for(var i = 0; i < rs.rows.length; i++) {
                            r += rs.rows.item(i).mapNumber + ", " + rs.rows.item(i).mapDifficulty + ", " + rs.rows.item(i).scoreHour + ':' + rs.rows.item(i).scoreMinute + ':' + rs.rows.item(i).scoreSecond + '\n' ;
                        }
                        print(r);
                        textArea.text = r;
                    }
                    )
    }
    

    }@

    I added this on .pro

    @folder_02.source = qml/Storage
    folder_02.target = qml
    DEPLOYMENTFOLDERS += folder_02@

    [Edit: Quieted title, please use normal text, UPPER case don't help solve issue faster /Vass]



  • THANKS!!!!!


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.