<div dir="ltr">Hi there,<div><br></div><div>I try to create an app in which I want to have an existing database bind in the binary.</div><div><br></div><div>My approach was the following: </div><div>in pro file:</div><div>
<font color="#000000">QT</font><span style="color:rgb(192,192,192)"> </span>+=<span style="color:rgb(192,192,192)"> </span>sql</div><div><pre style="margin-top:0px;margin-bottom:0px"><br></pre><pre style="margin-top:0px;margin-bottom:0px">
<pre style="margin-top:0px;margin-bottom:0px">database.files<span style="color:rgb(192,192,192)"> </span>=<span style="color:rgb(192,192,192)"> </span>stations.db</pre><pre style="margin-top:0px;margin-bottom:0px">database.path<span style="color:rgb(192,192,192)"> </span>=<span style="color:rgb(192,192,192)"> </span>/home/nemo/.local/share/harbour-qtimetable/harbour-qtimetable</pre>
<pre style="margin-top:0px;margin-bottom:0px">INSTALLS += database</pre><pre style="margin-top:0px;margin-bottom:0px"><br></pre><pre style="margin-top:0px;margin-bottom:0px">To open the database:</pre><pre style="margin-top:0px;margin-bottom:0px">
db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName(DB_NAME);
db.setUserName(USER_NAME);
db.setPassword(PASSWORD);
db.setConnectOptions("QSQLITE_OPEN_READONLY=1");<br></pre><pre style="margin-top:0px;margin-bottom:0px">if(db.open()) {...}</pre><pre style="margin-top:0px;margin-bottom:0px"><br></pre><pre style="margin-top:0px;margin-bottom:0px">
for DB_NAME I use QStandardPaths::writableLocation(QStandardPaths::DataLocation) with stations.db appended. </pre><pre style="margin-top:0px;margin-bottom:0px"><br></pre><pre style="margin-top:0px;margin-bottom:0px">However when I deploy this will fail as the path on emulator has</pre>
<pre style="margin-top:0px;margin-bottom:0px">home/deploy/installroot/ prefix, and when deploying on device there is /opt/sdk/..<br></pre><pre style="margin-top:0px;margin-bottom:0px">prefix. </pre><pre style="margin-top:0px;margin-bottom:0px">
<br></pre><pre style="margin-top:0px;margin-bottom:0px">This makes testing quite annoying, is there a genuine way to get the database to open both in the emulator and the device? </pre><pre style="margin-top:0px;margin-bottom:0px">
<br></pre><pre style="margin-top:0px;margin-bottom:0px">Side question is there a "standard path::datalocation" variable for the .pro file?</pre><pre style="margin-top:0px;margin-bottom:0px"><br></pre><pre style="margin-top:0px;margin-bottom:0px">
Thanks for any help,</pre><pre style="margin-top:0px;margin-bottom:0px">Lukas</pre></pre></div></div>