<?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[QT MAC  app cannot read SQLite database.]]></title><description><![CDATA[<p dir="auto">Database settings:</p>
<p dir="auto">In. h file.<br />
QSqlDatabase db;</p>
<p dir="auto">In the CPP file.<br />
This - &gt; DB = QSqlDatabase:: addDatabase ("QSQLITE");<br />
Db. setDatabaseName (". / realtest. db");</p>
<p dir="auto">Under win, debug, release. it's works well</p>
<p dir="auto">However, after migrating to Mac, it was normal at debug. However, after being published as app, the data could not be read.<br />
If absolute paths are adopted, such as:<br />
DB = QSqlDatabase:: addDatabase (ReadingSqlConst:: SQLITE);<br />
Db. setDatabaseName (QString ("/Users/apple/Desktop/newztdb/Resources/realtest.db");<br />
it's works well, but it's notwork if you take the following path</p>
<p dir="auto">Method 1:<br />
DB = QSqlDatabase:: addDatabase (ReadingSqlConst:: SQLITE);<br />
Db. setDatabaseName (QString (QApplication:: Application DirPath ()+"/ Resources / realtest. db");</p>
<p dir="auto">Method 2:<br />
QDir tempDir;<br />
QString current Dir = tempDir. current Path ();<br />
DB = QSqlDatabase:: addDatabase (ReadingSqlConst:: SQLITE);<br />
Db. setDatabaseName (currentDir +"/ Resources / realtest. db");<br />
Mode 1 and mode 2 are also abnormal.</p>
<p dir="auto">I just want to put sqlite's DB file in app. How can I solve it?</p>
]]></description><link>https://forum.qt.io/topic/105890/qt-mac-app-cannot-read-sqlite-database</link><generator>RSS for Node</generator><lastBuildDate>Fri, 17 Apr 2026 14:41:26 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/105890.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 13 Aug 2019 18:28:04 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to QT MAC  app cannot read SQLite database. on Tue, 13 Aug 2019 19:20:05 GMT]]></title><description><![CDATA[<p dir="auto">That's not what I wrote. I wrote that applications are usually stored in read-only folders so writing a database there will fail. Furthermore, these folders are usually machine centric which mean that depending on what you implement several users will read/write/overwrite data of other users.</p>
<p dir="auto">As for macOS see <a href="https://developer.apple.com/library/archive/documentation/FileManagement/Conceptual/FileSystemProgrammingGuide/FileSystemOverview/FileSystemOverview.html" target="_blank" rel="noopener noreferrer nofollow ugc">Apple's Filesystem Overview</a>.</p>
]]></description><link>https://forum.qt.io/post/546044</link><guid isPermaLink="true">https://forum.qt.io/post/546044</guid><dc:creator><![CDATA[SGaist]]></dc:creator><pubDate>Tue, 13 Aug 2019 19:20:05 GMT</pubDate></item><item><title><![CDATA[Reply to QT MAC  app cannot read SQLite database. on Tue, 13 Aug 2019 19:03:52 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/sgaist">@<bdi>sgaist</bdi></a> said in <a href="/post/546025">QT MAC app cannot read SQLite database.</a>:</p>
<blockquote>
<p dir="auto">Hi and welcome to devnet,</p>
<p dir="auto">You forgot to go up one folder from the application folder.</p>
<p dir="auto">However, that said, you are taking a wrong approach. Forcing the file to be at the same level as your executable is bound to fail in the future. Usually applications are installed in read-only directories be it Linux, macOS or Windows. You should rather use <a href="https://doc.qt.io/qt-5/qstandardpaths.html#writableLocation" target="_blank" rel="noopener noreferrer nofollow ugc">QStandardPaths::writableLocation</a> to get a folder that is specific for the user of the application.</p>
</blockquote>
<p dir="auto">Does that mean that I can't put sqlite db  in the  applications, but only in other directories, such as user documents? Is there any demo, I'll refer to it.</p>
]]></description><link>https://forum.qt.io/post/546039</link><guid isPermaLink="true">https://forum.qt.io/post/546039</guid><dc:creator><![CDATA[m2009]]></dc:creator><pubDate>Tue, 13 Aug 2019 19:03:52 GMT</pubDate></item><item><title><![CDATA[Reply to QT MAC  app cannot read SQLite database. on Tue, 13 Aug 2019 18:40:20 GMT]]></title><description><![CDATA[<p dir="auto">Hi and welcome to devnet,</p>
<p dir="auto">You forgot to go up one folder from the application folder.</p>
<p dir="auto">However, that said, you are taking a wrong approach. Forcing the file to be at the same level as your executable is bound to fail in the future. Usually applications are installed in read-only directories be it Linux, macOS or Windows. You should rather use <a href="https://doc.qt.io/qt-5/qstandardpaths.html#writableLocation" target="_blank" rel="noopener noreferrer nofollow ugc">QStandardPaths::writableLocation</a> to get a folder that is specific for the user of the application.</p>
]]></description><link>https://forum.qt.io/post/546025</link><guid isPermaLink="true">https://forum.qt.io/post/546025</guid><dc:creator><![CDATA[SGaist]]></dc:creator><pubDate>Tue, 13 Aug 2019 18:40:20 GMT</pubDate></item></channel></rss>