开发者

How to retrieve stacktrace or device crash logs in Qt?

I want to see the application stack trace or crash logs on device. Is there any in built functionality available for Qt?

We can have the app log开发者_高级运维s by writing to files or doing device debugging. But getting a stack trace is useful when an unknown/fatal error occurs while running the app on the target device.


There is no built-in solution for this, but (assuming you are using c++), google-breakpad provides a solution. The documentation is a little lacking, and it has trouble playing with Qt's (non-)handling of exceptions thrown in event handlers, but it can take care of most of the heavy lifting.

Responding to questions in other answer:

Gyp should be located in src\tools\gyp\gyp.bat. You will run something like the following:

src\tools\gyp\gyp.bat src\client\windows\breakpad_client.gyp --include=breakpad_include.gypi -Dwin_debug_RuntimeLibrary=3 -Dwin_release_RuntimeLibrary=2 --generator-output=..\build\google_breakpad

The breakpad_include.gypi file sets up special configuration that gyp should use. Mine looks like this:

{
  'target_defaults': {
    'configurations': {
      'Common_Base': {
        'msvs_settings': {
          'VCCLCompilerTool': {
            'TreatWChar_tAsBuiltInType': '0',
          },
        },
      },
    },
  },
}

This gets around a difference in how Qt and VS treat WChar. The other settings specify the runtime library to use. This has to match what Qt is using.


You have not specified which OS but on linux you can make it create a core file by this command

set ulimit -c unlimited

Put this into your .bashrc file or where is appropriate and whenever a crash occurs you will get a core dump of your application.

Then you can debug it using gdb.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜