Qt

On this page, we get you up and running with Sentry's SDK, so that it will automatically report errors and exceptions in your application.

Don't already have an account and Sentry project established? Head over to sentry.io, then return to this page.

Install

Sentry captures data by using an SDK within your application’s runtime.

The Qt integration is part of the sentry-native SDK, which currently supports Windows, macOS, Linux, and Android. Both Qt 5 and Qt 6 are supported.

To build the SDK, download the latest sources from the Releases page. The SDK is managed as a CMake 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.

For example (on macOS):

Copied
# Configure the cmake build into the `build` directory,
# with crashpad, and Qt integration (on macOS).
cmake -B build \
    -D SENTRY_BACKEND=crashpad \
    -D SENTRY_INTEGRATION_QT=YES \
    --config RelWithDebInfo \
    -S .

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

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

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

Configure

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

Copied
#include <QtWidgets>
#include <sentry.h>

int main(int argc, char *argv[])
{
    sentry_options_t *options = sentry_options_new();
    sentry_options_set_dsn(options, "https://examplePublicKey@o0.ingest.sentry.io/0");
    sentry_options_set_release(options, "my-project-name@2.3.12");
    sentry_init(options);

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

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

    return app.exec();
}

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

Verify

This snippet includes an intentional error, so you can test that everything is working as soon as you set it up:

The quickest way to verify Sentry in your Native application is by capturing a message:

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

To view and resolve the recorded error, log into sentry.io and open your project. Clicking on the error's title will open a page where you can see detailed information and mark it as resolved.

Help improve this content
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) to suggesting an update ("yeah, this would be better").