Important: Please read the Qt Code of Conduct -

Deploy sqlite database with application on OS X

  • hi,

    i want to deploy an existing sqlite database with my qt application on OS X. I read about inserting the database's path in OTHER_FILES in .pro file, but that does not work. Can anyone point me the right way? thanks.

  • Resource system should help you if I understood correctly your problem

  • There are several ways to do that. You can install additional files with qmake:

    "qmake reference":

    e.g. install it to /opt/myapp/1.0/mydatabase

    Or, you copy the sqlite database into your application bundle. You can access the path with some native Mac OS X calls, see "Accessing the Bundle Path" here:

    "Qt docs":

  • you can also make a shell script, and call it in the qmake_post_link event. The script can then copy it anywhere you want

  • I just want to include a database in my application. and of course I want users to be able to write/read in/from this database. is there any EASY way to do that with Qt Creator?

    if I include it in my resources, theres no database which I can see in my terminal....

  • If you need it only under Mac OSX then simpliest way is to put it into bundle, as harryF said. Not sure that it can be done via QtCreator, but it can be scripted easy one time and then used at each build.

  • hi,

    thanks for your help so far. but I don't get it. I tried adding

    @documentation.path = /Users/myUser/program/doc
    documentation.files = /Users/myUser/test/*
    INSTALLS += documentation@

    in my .pro file. That should copy all from ..../test into ..../program/doc, shouldn't it? I compiled it, but it does not. Perhaps anyone could help me out with some code. In my source directory i have a file named "teams.db", this should be copied into

    Of course I could move the file in after compiling with a terminal command, but it would be nice if there's another way in QtCreator (e.g. like in VisualStudio, where you can set files to be deployed beside the .exe). It would be great if that would work for windows, too.

  • @klaus - you have to run "make install" to copy the files. "make" will just build the binaries, but not deploy them.

  • hm ok, but it does not work. "make: *** No rule to make target `install'. Stop."

    "make" doesn't work either "make: Nothing to be done for `'."

    and: I'd like to run it from QtCreator and not do "make install" every time i want to test...

  • hi,

    i managed that. I also changed my .pro.user file and it now creates the application executable in the right directory, so that there's only one application directory, no matter if it's compiled with terminal or by Qt Creator. But if I execute my application from Qt Creator (by clicking on the green arrow), I get an error if I want to open a SQLite database.

    QSqlError(-1, "Error opening database", "unable to open database file")

    If I start the application manually (double click on the app in the directory), everything works well...

    Database path is "data/teams.tbl" relative to my application path.
    I open it with
    @QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE", "teams");

  • You may want to transport the database with your App bundle but some users may not have the permissions to write to that directory.
    So on first startup you could copy it to an appropriate destination.
    What is appropriate depends on the kind of application (sandboxed or not).


Log in to reply