PDA

View Full Version : Please help!! Segmentation fault in Qt



jmalicke
22nd July 2014, 18:33
I have a smallish-sized Qt application. The project compiles and runs great with no problems. When I add one line to the source code — adding an std::string in the MainWindow class definition — then I get a segmentation fault.

MainWindow.h (compiles and runs fine with no errors)


... other code ...
// std::string currentFilename
... other code ...

MainWindow.h


... other code ...
std::string currentFilename // uncomment this line
... other code ...

Result on application close is:


qUncompress: Input data is corrupted
** Process crashed **

I have never heard qUncompress and I am certainly not using it. I am trying to figure what kind of problem might be causing this bizarre behavior. I have a lot of code to post and it might be too much to read. I have tried running the program in valgrind and I get no non-external errors. I have also tried refactoring the project by removing pieces of functionality at a time and seeing if the problem is fixed. Unfortunately, this approach has led to nothing useful. I always get to these one liners in the MainWindow class definition where I can enable/disable the segmentation fault by commenting/uncommenting out the single line. Each time I try removing functionality and “starting over” it is a different single line in MainWindow class definition that causes the segmentation fault.

I try debugging the application but I cannot get a stack trace on explosion. I simply get 0×0 ???????????

d_stranz
23rd July 2014, 05:35
The std::string is almost certainly irrelevant to the crash. It's just the straw that breaks the camel's back, so to speak. Something in your MainWindow or app implementation is undoubtedly trashing the stack and your program wanders off into la-la land (n.b. your inability to get a stack trace), but it doesn't become apparent until you change the memory layout slightly by adding this extra member variable.

Look at how and where you are allocating memory in your MainWindow class. Are you using stack variables that go out of scope but which your code expects to be valid at a later time? Did you mistakenly redeclare a member variable as a local inside the constructor (thus hiding the real member variable)? Is everything properly initialized (especially pointers) before being used? Are you checking that all pointers are non-NULL before using them?

Finally, are all of the libraries you are linking to compiled with the same version of the compiler? Are you mixing up debug and release mode libraries or object files when linking or in runtime DLLs? Different versions of Qt?

Any of these things and more could cause the behaviour you are seeing.