Quote Originally Posted by ArKay View Post
This also crashes on me at sqlite3_backup_init. To isolate the problem I have created a small test program. sqlite3.h & .c are taken from the Qt 4.7.1. archive (the version I am developing with), somehow those files were missing in the OpenSUSE 11.4 Qt Source package.

This code tries to do an online backup of an opened database, so it's not from memory.

==12265== Thread 2:
==12265== Invalid write of size 8
==12265== at 0x438492: pthreadMutexEnter (sqlite3.c:15266)
==12265== by 0x4382F0: sqlite3_mutex_enter (sqlite3.c:14537)
==12265== by 0x454E0A: sqlite3_backup_init (sqlite3.c:45601)

Qt Code:
  1. #include <QtSql/QSqlDatabase>
  2. #include <QtSql/QSqlDriver>
  3. #include <QString>
  4. #include <QVariant>
  5. #include "sqlite3/sqlite3.h"
  6.  
  7. void backup(QString src, QString dst) {
  8. QSqlDatabase sqlDb = QSqlDatabase::addDatabase("QSQLITE");
  9. sqlDb.setDatabaseName(src);
  10. sqlDb.open();
  11.  
  12. QVariant v = sqlDb.driver()->handle();
  13. sqlite3* pSource = *static_cast<sqlite3 **>(v.data());
  14.  
  15. int rc;
  16. sqlite3 *pDest;
  17. sqlite3_backup *pBackup;
  18. rc = sqlite3_open(dst.toLocal8Bit().data(), &pDest);
  19. if(rc == SQLITE_OK) {
  20. pBackup = sqlite3_backup_init(pDest, "main", pSource, "main");
  21. if (pBackup) {
  22. do {
  23. rc = sqlite3_backup_step(pBackup, 5);
  24. if (rc == SQLITE_OK || rc == SQLITE_BUSY || rc == SQLITE_LOCKED) {
  25. sqlite3_sleep(250);
  26. }
  27. } while(rc == SQLITE_OK || rc == SQLITE_BUSY || rc == SQLITE_LOCKED );
  28.  
  29. /* Release resources allocated by backup_init(). */
  30. sqlite3_backup_finish(pBackup);
  31. }
  32. sqlite3_close(pDest);
  33. }
  34.  
  35. sqlDb.close();
  36. }
  37.  
  38.  
  39. int main(int argc, char *argv[]) {
  40. backup("/home/arkay/Projects/QtWebApp/database/Current/architektur.db",
  41. "/home/arkay/Projects/QtWebApp/database/Backup/architektur.db");
  42. }
To copy to clipboard, switch view to plain text mode 
dear
you need to search sqlite3.h in the qt src,and this is my dir "D:\Qt\5.15.1\Src\qtbase\src\3rdparty\sqlite", and then copy the sqlite3.h and sqlite3.c