---
title: "Qt"
description: "Learn how to use Sentry with Qt and capture your first events."
url: https://docs.sentry.io/platforms/native/guides/qt/
---

# Sentry for Qt

## [Prerequisites](https://docs.sentry.io/platforms/native/guides/qt.md#prerequisites)

You need:

* A Sentry [account](https://sentry.io/signup/) and [project](https://docs.sentry.io/product/projects.md)
* Your application up and running
* Qt5 or Qt6

The SDK currently supports **Windows**, **macOS**, and **Linux**.

## [Install](https://docs.sentry.io/platforms/native/guides/qt.md#install)

To build the SDK, download the latest sources from the [Releases page](https://github.com/getsentry/sentry-native/releases). The SDK is managed as a [CMake](https://cmake.org/cmake/help/latest/) project, which additionally supports several configuration options, such as the backend to use.

To enable the Qt integration set the `SENTRY_INTEGRATION_QT` option to `YES`.

##### Important

If the Qt libraries are not installed in one of the predefined `CMake` [system prefix paths](https://cmake.org/cmake/help/latest/variable/CMAKE_SYSTEM_PREFIX_PATH.html), where they can be found by `CMake`, you will need to set [`CMAKE_PREFIX_PATH`](https://cmake.org/cmake/help/latest/variable/CMAKE_PREFIX_PATH.html) explicitly.

For example:

```shell
# Configure the cmake build into the `build` directory,
# with the desired backend, and Qt integration.
cmake -B build \
    -D SENTRY_BACKEND=native \
    -D SENTRY_INTEGRATION_QT=YES

# Build the project
cmake --build build --parallel

# Install the resulting artifacts into a specific prefix
cmake --install build --prefix install

# Which will result in the following (on macOS):
eza --tree install --level 2
install
├── bin
│  └── sentry-crash
├── include
│  └── sentry.h
└── lib
   ├── cmake
   ├── libsentry.dylib
   └── libsentry.dylib.dSYM
```

You can configure the Qt build for Windows analogous to the [regular build instructions](https://docs.sentry.io/platforms/native.md#install).

##### Bundling out-of-process backends

The out-of-process *Native* and *Crashpad* backends require shipping `sentry-crash` or `crashpad_handler`, respectively, alongside the application binary. See the [Native](https://docs.sentry.io/platforms/native/configuration/backends/native.md) and [Crashpad](https://docs.sentry.io/platforms/native/configuration/backends/crashpad.md) backend documentation for more information.

## [Configure](https://docs.sentry.io/platforms/native/guides/qt.md#configure)

**Error Monitoring** starts working as soon as you call `sentry_init()`, capturing native crashes and the events you send manually. This guide also enables **Tracing** and **Release Health**.

Configuration should happen as early as possible in your application's lifecycle.

The snippet also turns on:

* Tracing: via [`traces_sample_rate`](https://docs.sentry.io/platforms/native/guides/qt/configuration/options.md#traces_sample_rate). You create transactions and spans with [custom instrumentation](https://docs.sentry.io/platforms/native/guides/qt/tracing/instrumentation/custom-instrumentation.md).
* Release Health: via [`release`](https://docs.sentry.io/platforms/native/guides/qt/configuration/options.md#release). The SDK starts a session on `sentry_init()` and ends it on `sentry_close()`.
* SDK debug output: via [`debug`](https://docs.sentry.io/platforms/native/guides/qt/configuration/options.md#debug). Turn this off in production.

Don't need a feature? Remove its options from the snippet.

```cpp
#include <QtWidgets>
#include <sentry.h>

int main(int argc, char *argv[])
{
    sentry_options_t *options = sentry_options_new();
    sentry_options_set_dsn(options, "https://<key>@o<orgId>.ingest.sentry.io/<projectId>");
    // This is also the default-path. For further information and recommendations:
    // https://docs.sentry.io/platforms/native/configuration/options/#database-path
    sentry_options_set_database_path(options, ".sentry-native");
    sentry_options_set_release(options, "my-project-name@2.3.12");
    sentry_options_set_debug(options, 1);
    // Enables Tracing.
    // Set to 1.0 to capture 100% of transactions for tracing.
    // We recommend reducing this value in production.
    sentry_options_set_traces_sample_rate(options, 1.0);
    sentry_init(options);

    // Make sure everything flushes
    auto sentryClose = qScopeGuard([] { sentry_close(); });

    QApplication app(argc, argv);
    QWidget widget;
    widget.show();

    return app.exec();
}
```

Alternatively, pass the DSN as `SENTRY_DSN` environment variable during runtime. This can be especially useful for server applications.

##### Important

Calling `sentry_close()` before exiting the application is critical. It ensures that events can be sent to Sentry before execution stops. Otherwise, event data may be lost.

### [Capture Qt Log Messages](https://docs.sentry.io/platforms/native/guides/qt.md#capture-qt-log-messages)

When you build the SDK with `SENTRY_INTEGRATION_QT=YES`, the Qt integration registers itself during `sentry_init()`. It records messages from `qDebug()`, `qInfo()`, `qWarning()`, `qCritical()`, and `qFatal()` as breadcrumbs, and still forwards them to any message handler you installed before.

### [Add Readable Stack Traces With Debug Information Files](https://docs.sentry.io/platforms/native/guides/qt.md#add-readable-stack-traces-with-debug-information-files)

To see symbolicated stack traces for native crashes, upload your application's debug information files to Sentry. See [Uploading Debug Information Files](https://docs.sentry.io/platforms/native/guides/qt/data-management/debug-files/upload.md) for how to do this with the Sentry CLI.

## [Verify Your Setup](https://docs.sentry.io/platforms/native/guides/qt.md#verify-your-setup)

Let's test your setup and confirm that Sentry is working correctly and sending data to your Sentry project.

Add this code snippet to capture a message:

```c
sentry_capture_event(sentry_value_new_message_event(
  /*   level */ SENTRY_LEVEL_INFO,
  /*  logger */ "custom",
  /* message */ "It works!"
));
```

### [View Captured Data in Sentry](https://docs.sentry.io/platforms/native/guides/qt.md#view-captured-data-in-sentry)

Now, head over to your project on [Sentry.io](https://sentry.io) to view the collected data (it takes a couple of moments for the data to appear).

## [Next Steps](https://docs.sentry.io/platforms/native/guides/qt.md#next-steps)

At this point, you should have integrated Sentry into your application. Here's what to explore next:

* Explore [practical guides](https://docs.sentry.io/get-started/guides.md) on what to monitor, log, track, and investigate after setup

Are you having problems setting up the SDK or integration?

* [Get support](https://www.sentry.help/en/)

## Other Native Frameworks

- [Google Breakpad](https://docs.sentry.io/platforms/native/guides/breakpad.md)
- [Google Crashpad](https://docs.sentry.io/platforms/native/guides/crashpad.md)
- [Minidumps](https://docs.sentry.io/platforms/native/guides/minidumps.md)
- [WebAssembly](https://docs.sentry.io/platforms/native/guides/wasm.md)

## Topics

- [Basic Configuration](https://docs.sentry.io/platforms/native/guides/qt/configuration.md)
- [Usage](https://docs.sentry.io/platforms/native/guides/qt/usage.md)
- [Data Management](https://docs.sentry.io/platforms/native/guides/qt/data-management.md)
- [Security Policy Reporting](https://docs.sentry.io/platforms/native/guides/qt/security-policy-reporting.md)
- [Debug Information](https://docs.sentry.io/platforms/native/guides/qt/debug-information.md)
- [Enriching Events](https://docs.sentry.io/platforms/native/guides/qt/enriching-events.md)
- [Tracing](https://docs.sentry.io/platforms/native/guides/qt/tracing.md)

---

Find other pages: [Sitemap](https://docs.sentry.io/sitemap.md) lists every page with a one-line summary, and [llms.txt](https://docs.sentry.io/llms.txt) gives an overview with guidance for agents.
