Skip to content
Aditya Bhalsod
← Open Source
Open SourceIntermediate

Building a Linux Clipboard Manager With C++20 and Qt 6

What I learned building clip-stacker, a tray app that keeps unlimited clipboard history in SQLite, pastes with a shortcut and ships as a ~125 KB binary.

  • #cpp
  • #qt
  • #linux
  • #sqlite
Contents
  1. Listening to the clipboard
  2. Storing history in SQLite
  3. Keep it local
  4. Pasting on behalf of the user
  5. Packaging
  6. What I'd tell someone starting a desktop tool

Windows 11 has a clipboard history panel on Win + V. I wanted the same on my Linux desktop, without an Electron app idling at 200 MB of RAM. The result is clip-stacker: a C++20 / Qt 6 tray app that compiles to roughly 125 KB.

Listening to the clipboard

Qt makes the capture side simple. QGuiApplication::clipboard() returns a QClipboard, and its dataChanged signal fires whenever anything new is copied.

C++
connect(QGuiApplication::clipboard(), &QClipboard::dataChanged, this, [this] {
    const QString text = QGuiApplication::clipboard()->text();
    if (!text.isEmpty() && text != m_lastText) {
        m_store.insert(text);
        m_lastText = text;
    }
});

The m_lastText check matters: some apps set the clipboard twice for one copy, and you don't want duplicate entries.

Storing history in SQLite

History lives in a single SQLite table with the content, a hash for de-duplication, and a timestamp. Qt's QSqlDatabase driver is enough; no ORM needed.

Keep it local

There's no telemetry and no network code at all. Clipboards contain passwords and private messages, so the only safe default is to never send them anywhere.

Pasting on behalf of the user

Showing history is half the job; the other half is pasting the chosen item into the window that was focused before the popup opened. On X11 that means:

  1. Put the selected item back on the clipboard.
  2. Hide the popup so focus returns to the previous window.
  3. Send a synthetic Ctrl + V with the XTest extension.

Packaging

Linux users install software in many ways, so releases are built by GitHub Actions in three package formats from one workflow. CMake handles the build, and each format is a separate job that uploads its artifact to the release.

What I'd tell someone starting a desktop tool

  • Pick a native toolkit if memory and startup time matter. Qt 6 is still excellent.
  • Write the storage layer first. Once history is reliable, the UI is the fun part.
  • Automate packaging on day one. Manual releases are where side projects go to die.

Found this useful? Share it with your team.

Keep reading

More from Open Source and beyond