There is a database ( SQLite3 with one table) for storing logins and passwords. There is a trivial interface, written in Qt, for adding / editing / deleting data lines in the database. Adding and editing is possible only when calling a modal dialog box (implemented, through QDataWidgetMapper).

Actually, the essence of the question: how to implement database backup (for example, so that when you run the application, a copy of the database is created)? Describe the algorithm of actions and what functions are needed for this .

enter image description here

APDATE: Connect the sources sqlite3.h sqlite3.c to the project. Wrote function for backup:

int DataBase::backupDb() { int rc; QVariant vHND = m_db.driver()->handle(); if(vHND.isValid() && qstrcmp(vHND.typeName(), "sqlite3*") == 0) { sqlite3 * handle = *static_cast<sqlite3 **>(vHND.data()); sqlite3 *pDb = handle; QByteArray array = DATABASE_NAME.toLocal8Bit(); const char * zFilename = array.data(); sqlite3 *pFile; sqlite3_backup *pBackup; rc = sqlite3_open(zFilename, &pFile); if( rc==SQLITE_OK ) { pBackup = sqlite3_backup_init(pFile, "main", pDb, "main"); if( pBackup ) { rc = sqlite3_backup_step(pBackup, -1); (void)sqlite3_backup_finish(pBackup); } rc = sqlite3_errcode(pFile); } (void)sqlite3_close(pFile); } return rc; } 

But, on the line: rc = sqlite3_backup_step(pBackup, -1); Error: "segmentation fault" crashes. WHAT'S WRONG?

ps I use the function when launching the application, after connecting to the database.

  • sqlite is a file, so you can just make a copy of it and indicate the current date and time in the title - gil9red
  • @ gil9red Are there any more "technical" methods? - Andrey
  • googling this: sqlite.org/backup.html - gil9red
  • About segmentation fault it is better to ask a separate question. With a complete, but minimal code example. The minimum reproducible example is jfs
  • @jfs error occurred due to a conflict with the database driver built into Qt. - Andrey

0