Skip to content
potluckdb

Qt

Electron · Tauri · Qt · Flutter · React Native · Capacitor and Ionic · .NET MAUI

A Qt application links the C SDK archive and includes the C++ facade. Qt supplies the application data directory and nothing else. Follow the C++ installation page, using the CMake below instead.

Qt 6 with a C++17 compiler and CMake, on macOS, Linux or Windows.

The C++ column of the compatibility matrix, packaged for Qt. Each release runs the quickstart on the platforms in this table. Other platforms have no verification for this integration.

PlatformTargetsPackage
macOSmacos-arm64, macos-x86_64potluckdb-c-sdk
Linuxlinux-x86_64-gnu, linux-arm64-gnu, linux-x86_64-musl, linux-arm64-muslpotluckdb-c-sdk
Windowswindows-x86_64, windows-arm64potluckdb-c-sdk
find_package(Qt6 REQUIRED COMPONENTS Core)
find_package(potluckdb CONFIG REQUIRED)
qt_add_executable(notes main.cpp)
target_link_libraries(notes PRIVATE Qt6::Core potluckdb::cpp)

Create CMakeLists.txt beside main.cpp. Put cmake_minimum_required(VERSION 3.16) on the first line. Put project(Notes LANGUAGES CXX) on the second line. Add the configuration above after these lines.

The archive’s potluckdb::cpp target links its shared runtime. Windows uses the corresponding import library.

To deploy the program:

  1. Copy the archive’s runtime and storage libraries beside the executable.
  2. On macOS and Linux, set a runtime search path relative to the executable: @executable_path on macOS, $ORIGIN on Linux.
  3. Deploy Qt’s libraries with Qt’s deployment tool for the platform.

In CMake, set the search path with the target’s BUILD_RPATH property, or with INSTALL_RPATH when you install with CMake. On macOS, macdeployqt needs an application bundle. Set the target’s MACOSX_BUNDLE property, and copy potluckdb’s libraries into the bundle’s Contents/MacOS directory.

windeployqt does not copy potluckdb’s libraries.

The program opens the database under Qt’s application data location, inserts a note and prints the table.

  1. Set CMAKE_PREFIX_PATH to the extracted C SDK directory and your Qt installation directory, separated by a semicolon.
  2. Configure and build the program.
Terminal window
cmake -S . -B build -DCMAKE_PREFIX_PATH="/opt/potluckdb-c-sdk-0.1.0-<target>;/path/to/Qt/6/<kit>"
cmake --build build
  1. On macOS and Linux, run ./build/notes.
  2. On Windows, run build\Debug\notes.exe with the DLLs described above.

It prints the notes and quickstart: ok. To choose a separate directory for this example, pass --data-dir /path/to/data.

main.cpp
// potluckdb in a Qt application: one database, opened where Qt keeps the application's data.
#include <QCoreApplication>
#include <QCommandLineParser>
#include <QDir>
#include <QStandardPaths>
#include <QTextStream>
#include "potluckdb.hpp"
int main(int argc, char *argv[]) {
QCoreApplication application(argc, argv);
QCoreApplication::setOrganizationName("example");
QCoreApplication::setApplicationName("notes");
QCommandLineParser parser;
parser.addOption({"data-dir", "Store this example's data in the supplied directory.", "directory"});
parser.process(application);
const QDir data(parser.isSet("data-dir") ? parser.value("data-dir")
: QStandardPaths::writableLocation(QStandardPaths::AppDataLocation));
data.mkpath(".");
QTextStream out(stdout);
try {
auto remote = potluckdb::Remote::from_directory(data.filePath("remote").toStdString()); // a bucket replaces this in production; see the C++ installation page
auto db = potluckdb::open(data.filePath("notes.potluckdb").toStdString(), remote);
db.execute("CREATE TABLE IF NOT EXISTS note(id INTEGER PRIMARY KEY, body TEXT NOT NULL)");
db.execute("INSERT INTO note(body) VALUES(?)", potluckdb::Bindings::positional({std::string("buy milk")}));
auto rows = db.query("SELECT id, body FROM note ORDER BY id");
for (const auto &row : rows) {
out << std::get<int64_t>(row["id"]) << ": " << QString::fromStdString(std::get<std::string>(row["body"])) << "\n";
}
db.close();
remote.close();
} catch (const potluckdb::Error &error) {
QTextStream(stderr) << error.code().c_str() << ": " << error.what() << "\n";
return 1;
}
out << "quickstart: ok\n";
return 0;
}

Each release builds and runs this program with Qt 6 on macOS, Linux and Windows.