boltZharp Docs
widgetsSDKs

Qt

For Qt Widgets and QML apps on Windows, macOS and Linux: crashes through Crashpad, Qt's warnings and qFatal, the screen the user was on, and your HTTP calls, each read as functions, files and lines from your build's debug files.

Zharp for Qt is Zharp for C and C++ with a small Qt layer on top, in the same package. Everything on that page applies: crashes through Crashpad, handled errors, user and tags, spans and logs. The Qt layer adds three things:

  • Qt's messages: qWarning and qCritical become breadcrumbs, and qFatal names the crash it ends in.
  • Screens: every crash, error, log and span says which screen the user was on, and the breadcrumbs show how they got there.
  • Network: QNetworkAccessManager calls as spans, with their headers and traceparent so your backend's trace continues them.

Install

Create an app from the Qt tile under Add app, on the Desktop tab. Qt 6.5 or later, or Qt 5.15; CMake 3.16 or later and a C++17 compiler (MSVC, Clang or GCC). On Linux the SDK uses libcurl (libcurl4-openssl-dev to build).

CMake

Add Zharp after find_package(Qt6 …): it sees Qt and builds its Qt layer, zharp::qt, for that Qt, along with Crashpad. For Qt 5, find Qt5 instead; -DZHARP_QT_MAJOR=5 picks it when both are installed.

find_package(Qt6 REQUIRED COMPONENTS Widgets Network)

include(FetchContent)
FetchContent_Declare(zharp
    GIT_REPOSITORY https://github.com/zharp-io/zharp-native-lib.git
    GIT_TAG v0.1.0)
FetchContent_MakeAvailable(zharp)       # after Qt: zharp::qt is built for that Qt

add_executable(shop main.cpp shop_window.cpp)
target_link_libraries(shop PRIVATE Qt6::Widgets zharp::qt)
zharp_add_crash_handler(shop)            # crashpad_handler next to shop after each build
zharp_upload_debug_files(shop APP <application id> INCLUDE_SOURCES)

Or build and install the SDK once and use find_package(zharp):

# The SDK, built with its Qt layer, from a checkout or a release archive
cmake -S zharp-native-lib -B build -DZHARP_QT=ON -DCMAKE_BUILD_TYPE=RelWithDebInfo
cmake --build build && cmake --install build --prefix /opt/zharp

# CMakeLists.txt
find_package(Qt6 REQUIRED COMPONENTS Widgets)
find_package(zharp CONFIG REQUIRED)      # zharp::qt is there when Qt is found
target_link_libraries(shop PRIVATE Qt6::Widgets zharp::qt)
zharp_add_crash_handler(shop)

qmake

Build the SDK once as shared libraries, with its Qt layer, and install it:

cmake -S zharp-native-lib -B build -DZHARP_QT=ON -DBUILD_SHARED_LIBS=ON -DCMAKE_BUILD_TYPE=RelWithDebInfo
cmake --build build && cmake --install build --prefix /opt/zharp

Then include its .pri file in your .pro. It adds the include path, links zharp_qt and zharp, and copies crashpad_handler (and on Windows the SDK's DLLs) next to your executable after each link:

QT += widgets
SOURCES += main.cpp shop_window.cpp
CONFIG += force_debug_info              # debug info in release builds, for readable stacks
include(/opt/zharp/share/zharp/zharp_qt.pri)

Shipping

Ship crashpad_handler (crashpad_handler.exe on Windows) next to your executable, where the SDK looks for it: install(PROGRAMS $<TARGET_FILE:zharp::crashpad_handler> DESTINATION bin). windeployqt and macdeployqt don't know about it, so copy it into the folder (or Contents/MacOS) they produce. In a macOS bundle, sign it with the app.

Initialize

Start Zharp first thing in main, then hand ZharpQt::init the application object once it exists:

#include <zharp.hpp>
#include <zharp_qt.h>

int main(int argc, char **argv) {
    zharp_options_t options;
    zharp_options_init(&options);
    options.key = "zpk_…";                  // or ZHARP_KEY in the environment
    options.environment = "production";
    options.release = "1.4.2";
    zharp::Init zharp(&options);            // sends what's left when main returns

    QApplication app(argc, argv);
    ZharpQt::init(app);                     // Qt's messages, screens

    ShopWindow window;
    window.show();
    return app.exec();
}

The options and their ZHARP_* variables are the C and C++ SDK's: see Options. Each launch is a session.

Crashes

Crashpad's handler, a separate process, writes a minidump and sends it, with the release, environment, session, user, screen and the last 100 breadcrumbs. A crash that ends in qFatal reads as qFatal with its message, not as SIGABRT:

qFatal: payment methods table is missing (schema 7)
#0  zharp::qt::message_handler(QtMsgType, QMessageLogContext const&, QString const&) (src/qt/zharp_qt.cpp:55) [qt_shop +0x14900]
#1  libQt6Core.so.6 +0x133fab
#2  libQt6Core.so.6 +0x12aefa
#3  QMessageLogger::fatal(char const*, ...) const [libQt6Core.so.6 +0xdcd32]
#4  CheckoutDialog::loadPaymentMethods() (widgets/shop_window.cpp:49) [qt_shop +0xd5b0]
#5  operator() (widgets/shop_window.cpp:38) [qt_shop +0xd5b8]
#6  operator() (QtCore/qobjectdefs_impl.h:141) [qt_shop +0xd5b8]
…
#12 QObject::event(QEvent*) [libQt6Core.so.6 +0x1d5e17]
  • The stack is the one recorded where qFatal was called: the abort that follows runs inside the C library and Qt, where a crash dump alone can't be followed back to your code. Here the issue points at CheckoutDialog::loadPaymentMethods(), line 49.
  • Qt's own libraries (Qt6Core.dll, libQt6Widgets.so.6, QtGui.framework), Zharp's message handler, moc's generated code and what was inlined from Qt's headers are named but never count as your code, so the issue points at the first frame that is yours.
  • Crashes group by function names, so the same bug in two builds is one issue once both have symbols.
  • Under Advanced on the issue: the OS and CPU, the other threads, the loaded modules, and Download minidump.

Qt's messages

ZharpQt::init installs a message handler; the handler that was there before (Qt's own output, or yours) still runs after it.

qWarning("payment provider is slow (%d ms)", 2300);   // a breadcrumb; a log with ZHARP_LOGS=true
qCCritical(cartCategory) << "total is negative";         // "shop.cart: total is negative"
qFatal("payments.db is missing");                         // the crash reads "qFatal: payments.db is missing"
MessageWhat Zharp does
qDebug, qInfoNothing
qWarningA breadcrumb; a log (warn) with ZHARP_LOGS=true
qCriticalA breadcrumb; a log (error) with ZHARP_LOGS=true
qFatalNames the crash Qt ends in. With crash reporting off, it is sent as an error before Qt aborts

A message from a logging category other than default keeps its name in front: qt.network.ssl: …. Logs are off by default because the Zharp agent brings in the log files your app writes; the breadcrumbs go with every crash and error either way.

Screens

Every crash, error, log and span carries screen.name: where the user was. Each change is a navigation breadcrumb, ShopWindow → CheckoutDialog, so a crash shows the way there.

The user is onscreen.name
A QWidget windowIts class: CheckoutDialog (a class with Q_OBJECT); for Qt's own classes, its objectName, else its title
A QML page in a StackViewThe page on top, innermost StackView first: its objectName, else its QML type (PaymentPage)
A QQuickViewIts QML file: Main.qml → Main
An ApplicationWindow without a StackViewIts objectName, QML type or title

Menus, tooltips and splash screens leave the screen as it was. For navigation Zharp can't see:

// Navigation Zharp can't see: a QStackedWidget's pages, your own router
connect(stack, &QStackedWidget::currentChanged, this, [this](int) {
    ZharpQt::setScreen(stack->currentWidget()->objectName());
});

// Or name every screen yourself
ZharpQt::Options options;
options.screens = false;
ZharpQt::init(app, options);

Network

ZharpQt::NetworkAccessManager is a QNetworkAccessManager that records each HTTP call as a client span. Use it wherever you create one; for QML, ZharpQt::instrument(engine) gives the engine one, so XMLHttpRequest and remote images are traced too.

ZharpQt::NetworkAccessManager network;   // in place of QNetworkAccessManager

QNetworkRequest request(QUrl("https://api.example.com/orders?page=2"));
request.setRawHeader("Authorization", "Bearer …");
QNetworkReply *reply = network.get(request);
// span "GET api.example.com": url.full https://api.example.com/orders, status, headers,
// Authorization [REDACTED]; the request carries traceparent
  • The span is named by method and host, with the URL without its query string, the status code and the error.
  • Request and response headers are recorded, with authorization, cookies, tokens, API keys and sessions kept as [REDACTED].
  • A traceparent header goes with the request, so a backend that Zharp traces continues the same trace. Calls inside a zharp::Span are its children.
  • qrc:, file: and data: URLs aren't traced.

Readable stack traces

Crashes and errors hold addresses, not names. Build with debug information: RelWithDebInfo, /Zi with /DEBUG on MSVC, or CONFIG += force_debug_info with qmake; you don't ship it. With CMake, zharp_upload_debug_files uploads each release build's symbols after it links, with ZHARP_AUTH_TOKEN (a workspace API key with the Build uploads scope) and Node.js in the build's environment. With qmake, or in CI, run the CLI on the build folder:

npx @zharp/cli debug-files upload build/ --app <application id> --include-sources

Qt's own libraries don't need uploading: their frames are named from the module list and never count as your code. Upload them too (Qt's debug-info packages) if you want their functions named.

info
Shared builds
With a shared build of the SDK (qmake, or BUILD_SHARED_LIBS), zharp and zharp_qt are libraries of their own; their frames never count as your code, so they don't need uploading either.

Troubleshooting

  • No zharp::qt target: add Zharp after find_package(Qt6 …), or set -DZHARP_QT=ON.
  • "crash reporting is off: Crashpad's handler isn't at …": ship crashpad_handler next to the executable (after windeployqt or macdeployqt too), or set ZHARP_HANDLER_PATH.
  • screen.name is a Qt class (QDialog): give your window class Q_OBJECT, or an objectName.
  • Nothing arrives: run with ZHARP_DEBUG=true; the SDK prints what it sends and any refusal.