Qt

We can use LiteSync with the QSQLITE driver


Installation

First follow the instructions to compile and install LiteSync from the source code or use the pre-compiled binaries for your platform. You can start with the free version.


Linux

Modify the driver to use the LiteSync library:

sudo apt install patchelf

cd /usr/lib/x86_64-linux-gnu/qt5/plugins/sqldrivers

sudo patchelf --replace-needed libsqlite3.so.0 liblitesync.so libqsqlite.so

Instead of x86_64-linux-gnu it can be i386-linux-gnu or arm-linux-gnueabihf, it depends on the architecture


To check if it was successful:

ldd libqsqlite.so

It should appear liblitesync.so on the list.


Windows

Replace the file sqlite3.dll with the one containing LiteSync.



Example code
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName("file:data.db?node=secondary&connect=tcp://server:port");
if (!db.open()) {
  qDebug() << "Can't Connect to DB!";
}

QSqlQuery query;
QString result;
do {
  query.exec("PRAGMA sync_status");
  query.first();
  result = query.value(0).toString();
} while (!result.contains("\"db_is_ready\": true"));

A complete working example is available here