Search code examples
c++qtqmake

QT Creator copies SQLite as empty database


I have a sqlite file in the folder of my QT creator app. I even did Projects (right click) -> add existing files, and added it to my project. The file gets copied to the build directory. However, it contains no tables or data. I need the data in my database file to persist during the copy. Is there any way to ensure this?


Solution

  • What happens is that the database is not being copied, since attaching it to the .pro does not imply that it will be moved to the build folder.

    And then why is there .db in the build folder?

    sqlite if it does not find the .db it will create it, so you get the empty file.

    The solution is to implement a command that you copy:

    COPY_CONFIG = mydatabase.db
    copy_cmd.input = COPY_CONFIG
    copy_cmd.output = ${QMAKE_FILE_IN_BASE}${QMAKE_FILE_EXT}
    copy_cmd.commands = $$QMAKE_COPY_DIR ${QMAKE_FILE_IN} ${QMAKE_FILE_OUT}
    copy_cmd.CONFIG += no_link_no_clean
    copy_cmd.variable_out = PRE_TARGETDEPS
    QMAKE_EXTRA_COMPILERS += copy_cmd