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. Using SQLite in QML (Can read, but can't write)
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved QML and Qt Quick
2 Posts 1 Posters 3.5k 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.
  • J Offline
    J Offline
    JekHomie
    wrote on last edited by
    #1

    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]

    1 Reply Last reply
    0
    • J Offline
      J Offline
      JekHomie
      wrote on last edited by
      #2

      THANKS!!!!!

      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