Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

How to create mulitple database connections for a shared cache memory SqliteDB in Qt?



  • I want to create a shared cache memory SqliteDB(https://www.sqlite.org/inmemorydb.html) in a process, and use different connections in a few threads to query that SqliteDB.
    But when I followed example use to open the DB, I got the the error.
    My code:
    QSqlDatabase db;
    db = QSqlDatabase::addDatabase("QSQLITE");
    db.setDatabaseName(file::memory:?cache=shared);
    if(!db.open())
    {
    qDebug() << db.lastError().text();
    }
    How to create a shared sqliteDb, and create several connetions to this shared database?

    Thanks!
    Heiduc



  • I got it,
    1 setConnectOptions("QSQLITE_OPEN_URI;QSQLITE_ENABLE_SHARED_CACHE") ;
    2 setDatabaseName("file::memory:");
    3 QSqlDatabase::cloneDatabase


Log in to reply