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.
Requirements
Section titled “Requirements”Qt 6 with a C++17 compiler and CMake, on macOS, Linux or Windows.
What ships
Section titled “What ships”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.
| Platform | Targets | Package |
|---|---|---|
| macOS | macos-arm64, macos-x86_64 | potluckdb-c-sdk |
| Linux | linux-x86_64-gnu, linux-arm64-gnu, linux-x86_64-musl, linux-arm64-musl | potluckdb-c-sdk |
| Windows | windows-x86_64, windows-arm64 | potluckdb-c-sdk |
Install
Section titled “Install”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:
- Copy the archive’s runtime and storage libraries beside the executable.
- On macOS and Linux, set a runtime search path relative to the executable:
@executable_pathon macOS,$ORIGINon Linux. - 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.
Quickstart
Section titled “Quickstart”The program opens the database under Qt’s application data location, inserts a note and prints the table.
- Set
CMAKE_PREFIX_PATHto the extracted C SDK directory and your Qt installation directory, separated by a semicolon. - Configure and build the program.
cmake -S . -B build -DCMAKE_PREFIX_PATH="/opt/potluckdb-c-sdk-0.1.0-<target>;/path/to/Qt/6/<kit>"cmake --build build- On macOS and Linux, run
./build/notes. - On Windows, run
build\Debug\notes.exewith 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.
// 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;}Verified by the release
Section titled “Verified by the release”Each release builds and runs this program with Qt 6 on macOS, Linux and Windows.