SamuelNLP
SamuelNLP

Reputation: 4136

Segmentation fault (core dumped) in Qt5 application

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.

Upvotes: 0

Views: 6740

Answers (1)

Some programmer dude
Some programmer dude

Reputation: 409166

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.

Upvotes: 6

Related Questions