Segmentation fault (core dumped) in Qt5 application

一笑奈何 提交于 2019-12-23 05:59:37

问题


I have a Qt5 application that runs fine in the qtcreator, but if I try to run in by the executable created through terminal I get

Segmentation fault (core dumped)

I've tried in debug mode in Qt but no errors.


回答1:


If a program crashes when run outside of a debugger, but doesn't crash when run inside the debugger, it might be a sign that you are using uninitialized data. More specifically, an uninitialized pointer.

Debuggers generally clears all data, including local variables. That means that e.g. a pointer will be NULL when run in the debugger. But if you don't initialize some local variable, its contents will be indeterminate when run outside of the debugger, and your check against NULL will say "this is not NULL, please continue", and you will reference this uninitialized pointer and enter the territory of undefined behavior.

You need to go through all local variables, especially pointers, and make sure you initialize them before using them.



来源:https://stackoverflow.com/questions/20199873/segmentation-fault-core-dumped-in-qt5-application

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!