Giter Site home page Giter Site logo

bak-jh / qt-breakpad Goto Github PK

View Code? Open in Web Editor NEW

This project forked from wk8/qt-breakpad

0.0 0.0 0.0 19 KB

A light wrapper around Google's Breakpad to be used in Qt applications (http://qt.io)

License: Apache License 2.0

C++ 57.58% QMake 42.42%

qt-breakpad's Introduction

Credit goes to JPNaude

Qt Breakpad

A little wrapper around Google's Breakpad to be used in Qt5 projects, to make it platform-independent.

For now, only supports Linux and Windows (please open an issue, or even better, a pull request, to support other OSes).

Usage

Checkout this repo in your app's folder, e.g. (but not necessarily) as a submodule (and the path is up to you, too):

git submodule add [email protected]:wk8/qt-breakpad.git qt-breakpad
git submodule update --init --recursive

In your Qt project's *.pro file, include qt-breakpad's pri file:

include(qt-breakpad/qt-breakpad.pri)

In your application's main, before doing anything else, initialize the handler:

#include "qt_breakpad.h"

int main(int argc, char *argv[]) {
    QString reportPath = QDir::current().absolutePath(); // or whatever else you want, but it must exist
    QtBreakpad::init(reportPath);

    // ... your app's code starts here

    return 0;
}

Now if your app crashes, a dmp file will be generated in the given path.

If you want to send the said dump to some server, you can do that by passing a google_breakpad::ExceptionHandler::MinidumpCallback to QtBreakpad::init; or keep reading!

Real-life example

We also provide a wrapper around google_breakpad::ExceptionHandler::MinidumpCallbacks in the usual case where you simply want to access the minidump file to send it; that's

typedef bool (*QMinidumpCallback)(QFile& minidumpFile, void* context);

that can be passed a second argument to QtBreakpad::init.

It should return true if and only if it has successfully done its job (in which case no further Breakpad handlers that might have been defined will be called).

A more complicated example than above, that uses context object, and retrieves the contents of the minidump file and encodes it to base 64:

#include "qt_breakpad.h"

class MyContext
{
  public:
    QDateTime appStartedAt;
}

bool myQtBreakpadCallback(QFile &minidumpFile, void* context)
{
  MyContext* myContext = (MyContext*) context;

  QFileInfo fileInfo(minidumpFile);

  qDebug("From myQtBreakpadCallback; minidump file at " + fileInfo.absoluteFilePath());
  qDebug("My app had started at " + myContext->appStartedAt.toString());

  minidumpFile.open(QIODevice::ReadOnly);
  QByteArray rawMinidumpContent = minidumpFile.readAll();
  QString minidumpContent = rawMinidumpContent.toBase64();

  // ... actually upload it somewhere

  return true;
}

int main(int argc, char *argv[]) {
    QString reportPath = QDir::current().absolutePath(); // or whatever else you want, but it must exist

    MyContext myContext;
    myContext.appStartedAt = QDateTime::currentDateTimeUtc();

    QtBreakpad::init(reportPath, myQtBreakpadCallback, &myContext);

    // ... your app's code starts here

    return 0;
}

Analyzing the dumps

See here.

qt-breakpad's People

Contributors

icemanpro avatar wk8 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.