Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. 3rd Party Software
  4. Qt SQL driver plugin for SQLCipher ( for Qt 5 )

Qt SQL driver plugin for SQLCipher ( for Qt 5 )

Scheduled Pinned Locked Moved Unsolved 3rd Party Software
6 Posts 4 Posters 1.7k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    BB44
    wrote on 30 Mar 2023, 17:48 last edited by
    #1

    I have SQLite database in my qt app and i want to enctypt it. The one free solution is to use SQLCipher plugin for this purpose. I have found this plugin on github and i have successfully built it with MSYS2 MinGW64 following these instructions:

    git clone https://github.com/sjemens/qsqlcipher-qt5.git
    cd c:/temp/qsqlcipher-qt5
    mkdir -p build && cd build
    qmake ../qsqlcipher.pro
    make
    make install
    

    What hava i to do next to use this plugin like this:

    #include <QCoreApplication>
    #include <QSqlDatabase>
    #include <QSqlQuery>
    #include <QDebug>
    #include <QString>
    int main(int argc, char *argv[]) {
        QCoreApplication a(argc, argv);
        qDebug() << QSqlDatabase::drivers();
        QSqlDatabase db = QSqlDatabase::addDatabase("QSQLCIPHER");
        db.setDatabaseName("C:/sqlcipher/encrypted.db");
        db.open();
        QSqlQuery q;
        q.exec("PRAGMA key = 'testkey';");
        q.exec("insert into testtable (id,name) values(4,'dummy')");
        q.exec("SELECT id,name anz FROM testtable");
        while (q.next()) {
            QString id = q.value(0).toString();
            QString name = q.value(1).toString();
            qDebug() << "id=" << id << ",  name=" << name;
        }
        db.close();
        return 0;
    }
    

    I'm doing it in Windows 10 and in QT 5.15.2
    Help pls.

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 30 Mar 2023, 18:45 last edited by
      #2

      Hi and welcome to devnet,

      What exactly is the question ?
      In any case, you should add error checking to your SQL queries calls.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      B 1 Reply Last reply 30 Mar 2023, 21:03
      0
      • S SGaist
        30 Mar 2023, 18:45

        Hi and welcome to devnet,

        What exactly is the question ?
        In any case, you should add error checking to your SQL queries calls.

        B Offline
        B Offline
        BB44
        wrote on 30 Mar 2023, 21:03 last edited by BB44
        #3

        @SGaist Hi, thanks for answer.
        when i run this program i'm getting this app output:

        QSqlDatabase: QSQLCIPHER driver not loaded
        QSqlDatabase: available drivers: QSQLITE QODBC QODBC3 QPSQL QPSQL7
        Cannot open database: QSqlError("", "Driver not loaded", "Driver not loaded")
        

        What should i do to get QSQLCIPHER driver loaded? I tried to move the containing of C:\temp\qsqlcipher-qt5-5.15-2\3rdparty in C:\Qt\5.15.2\Src\qtbase\src\3rdparty directory, containing of
        C:\temp\qsqlcipher-qt5-5.15-2\qsqlcipher in C:\Qt\5.15.2\Src\qtbase\src\plugins\sqldrivers directory, and containing of C:\temp\qsqlcipher-qt5-5.15-2\build\qsqlcipher\plugins\sqldrivers
        in C:\Qt\5.15.2\Src\qtbase\src\plugins\sqldrivers directory (files libqsqlcipher.dll.a, qsqlcipher.dll, qsqlcipher.dll.debug). But it doesn't work anyway. You can check containing of these folders (except build) in github.

        S F 2 Replies Last reply 1 Apr 2023, 19:22
        0
        • B BB44
          30 Mar 2023, 21:03

          @SGaist Hi, thanks for answer.
          when i run this program i'm getting this app output:

          QSqlDatabase: QSQLCIPHER driver not loaded
          QSqlDatabase: available drivers: QSQLITE QODBC QODBC3 QPSQL QPSQL7
          Cannot open database: QSqlError("", "Driver not loaded", "Driver not loaded")
          

          What should i do to get QSQLCIPHER driver loaded? I tried to move the containing of C:\temp\qsqlcipher-qt5-5.15-2\3rdparty in C:\Qt\5.15.2\Src\qtbase\src\3rdparty directory, containing of
          C:\temp\qsqlcipher-qt5-5.15-2\qsqlcipher in C:\Qt\5.15.2\Src\qtbase\src\plugins\sqldrivers directory, and containing of C:\temp\qsqlcipher-qt5-5.15-2\build\qsqlcipher\plugins\sqldrivers
          in C:\Qt\5.15.2\Src\qtbase\src\plugins\sqldrivers directory (files libqsqlcipher.dll.a, qsqlcipher.dll, qsqlcipher.dll.debug). But it doesn't work anyway. You can check containing of these folders (except build) in github.

          S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 1 Apr 2023, 19:22 last edited by
          #4

          Start your application with the QT_DEBUG_PLUGINS environment variable set to 1 to see why the plugin fails to load.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • B BB44
            30 Mar 2023, 21:03

            @SGaist Hi, thanks for answer.
            when i run this program i'm getting this app output:

            QSqlDatabase: QSQLCIPHER driver not loaded
            QSqlDatabase: available drivers: QSQLITE QODBC QODBC3 QPSQL QPSQL7
            Cannot open database: QSqlError("", "Driver not loaded", "Driver not loaded")
            

            What should i do to get QSQLCIPHER driver loaded? I tried to move the containing of C:\temp\qsqlcipher-qt5-5.15-2\3rdparty in C:\Qt\5.15.2\Src\qtbase\src\3rdparty directory, containing of
            C:\temp\qsqlcipher-qt5-5.15-2\qsqlcipher in C:\Qt\5.15.2\Src\qtbase\src\plugins\sqldrivers directory, and containing of C:\temp\qsqlcipher-qt5-5.15-2\build\qsqlcipher\plugins\sqldrivers
            in C:\Qt\5.15.2\Src\qtbase\src\plugins\sqldrivers directory (files libqsqlcipher.dll.a, qsqlcipher.dll, qsqlcipher.dll.debug). But it doesn't work anyway. You can check containing of these folders (except build) in github.

            F Offline
            F Offline
            fkjslaasdhjfkhjsdjku
            wrote on 30 Apr 2023, 16:46 last edited by
            #5

            @BB44
            If it didn't solve the problem. I did so. I am using qt 6.5.0. But, I think, there will be no difference if you use qt 5 version. I compiled the sqlcipher dll library through vcpkg, but I couldn't build it from the sources. I created my own sqlcipher driver class using the source code of the sqlite driver, which is in the sources, changed only the name of the driver class and the paths inside the source files, added the SqlDriverCreator class, registered the new driver in the code:

            sqldrvcreator = new SqlDriverCreator;
            QSqlDatabase::registerSqlDriver("SQLITECIPHER", sqldrvcreator);,
            

            After that everything works. You can also create a plugin project and build the plugin dll library and drop one dll file into the release folder with the project in the release_dir\plugins\sqldrivers folder and it should work without registering the driver and including libraries in the pro file.

            1 Reply Last reply
            0
            • P Offline
              P Offline
              pourjour
              wrote on 17 Mar 2025, 19:35 last edited by
              #6

              check this repo: I've made a fork for this repo to make it work with Qt6
              https://github.com/pourjour/qsqlcipher/tree/main

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved