Please help!! Segmentation fault in Qt
-
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 0x0 ???????????
-
Could you put backtrace and/or source of the crash.
If backtrace is not generated then put qDebug() in all suspicious places and track the crash source. -
Using backtrace gives me:
0×0 ???????????
I do not have any suspicious places to look at besides the compiler generated destructor for MainWindow.
-
If you run app under debugger and step over source code what is last line before the explosion?
-
It sounds like you have a corrupted stack. It isn't the std string that is causing the problem, just the line that is making it show up.
More than likely you are writing to a bad pointer somewhere in your code and that pointer happens to be pointing into your stack and screwing it up.
Also another thing that can cause that type of weird behavior is a bad build. Trying doing a make distclean;qmake;make to rebuild your code completely. If the problem goes away you had a bad build.
-
I see. Valgrind doesn't pick anything up so it's made this problem excruciatingly difficult.
-
If you run it on Linux. Try it on Windows or OS X and vice versa.
Another compiler may produce some warnings.
Also try to enable all possible warnings in a compiler.
If the code is not very big you may put it here. Few extra pairs of eyes may find something. -
Yea if you can post the code.
Also to exapnd on andreyc's post, try (assuming gcc or mingw or compatible compiler) adding -Wall to turn warning level to all. If you get any warnings they made lead you to the culprit. And either way you really should fix all warnings. 99% of them are legit concerns and should be addressed for good code writing. :)
You can and should add:
@
CONFIG += warn_on
@to your project file as well.