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. Qml: How to use your own .db file
Forum Updated to NodeBB v4.3 + New Features

Qml: How to use your own .db file

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
1 Posts 1 Posters 253 Views
  • 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.
  • M Offline
    M Offline
    Miitt1
    wrote on last edited by
    #1

    Good day!
    I am new to qml, so I'm sorry if it's a dumb question.
    I am currently learning a way to connect my own .db file to qml.
    I have found that I should use QtQuick.LocalStorage 2.0 as a way to connect my db to qml.
    From what I understand from the documentation is that you can use QQmlEngine::offlineStoragePath() to find the path of the storage location where you can find and put the database. My database file name is test.db
    This is my test code if I can display the data.

    import QtQuick 2.12
    import QtQuick.Window 2.12
    import QtQuick.LocalStorage 2.15
    
    Window {
        width: 640
        height: 480
        visible: true
        title: qsTr("Hello World")
        Text {
            id: name
            //to find the path
            text: offlineStoragePath
        }
        Item {
            Component.onCompleted: {
                var db = LocalStorage.openDatabaseSync("test", "1.0", "Example database", 10000);
                db.transaction( function(tx) {
                    var result = tx.executeSql('select * from test');
                    for(var i = 0; i < result.rows.length; i++) {
                            print(result.rows[i].text);
                        }
                    });
            }
        }
    
    }
    
    

    Then the error "no such table: test Unable to execute statement" appears.
    I had also checked the db file and run "SELECT * FROM test" on the sqlite browser and it works fine.
    Any ideas and suggestions can help me, and if there's a better way of doing it can also help.
    Thank you very much for your time.

    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