Embedded Database in Qt

那年仲夏 提交于 2019-11-29 13:48:07

Even if you solve you compilation problems, embedding a sqlite database in the qrc file will not work. See e.g. the discussion in the Qt Centre Forum or on the Qt-interest mailing list. The best solution would be IMHO to include a dump of a database in the qrc file, create a memory sqlite db and rebuild the database from the SQL statements in the resource.

Volomike

I at least know how to do this on Mac OSX, where the QMAKE_BUNDLE_DATA parameter works. For Windows, check out this answer.

  1. Create a directory called "data" in your project directory.
  2. Put your database file in there.
  3. In your .pro file, add this section:

    mac { Resources.files = data Resources.path = Contents/MacOS QMAKE_BUNDLE_DATA += Resources }

  4. Now when you rebuild your application, it will be located in the Contents/MacOS/data folder. Thus, you could do something like this if your database was named custom.db:

    db.setDatabaseName(QCoreApplication::applicationDirPath().append("/data/custom.db"));
    

It seems that you removed or renamed your db file Shipping.db3 and added ShippingData.db3. To fix this build issue you should delete your build folder and rebuild project. This should solve your build issue.

Database deployment instructions you can read here: http://discussion.forum.nokia.com/forum/showthread.php?202894-Add-existing-Sqlite-database-to-Qt-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!