<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Qml: How to use your own .db file]]></title><description><![CDATA[<p dir="auto">Good day!<br />
I am new to qml, so I'm sorry if it's a dumb question.<br />
I am currently learning a way to connect my own .db file to qml.<br />
I have found that I should use QtQuick.LocalStorage 2.0 as a way to connect my db to qml.<br />
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<br />
This is my test code if I can display the data.</p>
<pre><code>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 &lt; result.rows.length; i++) {
                        print(result.rows[i].text);
                    }
                });
        }
    }

}

</code></pre>
<p dir="auto">Then the error  "no such table: test Unable to execute statement" appears.<br />
I had also checked the db file and run "SELECT * FROM test" on the sqlite browser and it works fine.<br />
Any ideas and suggestions can help me, and if there's a better way of doing it can also help.<br />
Thank you very much for your time.</p>
]]></description><link>https://forum.qt.io/topic/120874/qml-how-to-use-your-own-db-file</link><generator>RSS for Node</generator><lastBuildDate>Mon, 07 Sep 2026 14:38:21 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/120874.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 16 Nov 2020 08:58:19 GMT</pubDate><ttl>60</ttl></channel></rss>