Results 1 to 2 of 2

Thread: Please help!! Segmentation fault in Qt

  1. #1
    Join Date
    Jun 2014
    Posts
    30
    Thanks
    4
    Qt products
    Qt5

    Default 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)
    Qt Code:
    1. ... other code ...
    2. // std::string currentFilename
    3. ... other code ...
    To copy to clipboard, switch view to plain text mode 

    MainWindow.h

    Qt Code:
    1. ... other code ...
    2. std::string currentFilename // uncomment this line
    3. ... other code ...
    To copy to clipboard, switch view to plain text mode 

    Result on application close is:

    Qt Code:
    1. qUncompress: Input data is corrupted
    2. ** Process crashed **
    To copy to clipboard, switch view to plain text mode 

    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 ???????????

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Please help!! Segmentation fault in Qt

    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.

Similar Threads

  1. Segmentation Fault
    By Ryan Riffle in forum Qt Programming
    Replies: 4
    Last Post: 16th January 2011, 21:52
  2. segmentation fault!!
    By Yayati.Ekbote in forum Qt Programming
    Replies: 4
    Last Post: 24th March 2010, 16:10
  3. Segmentation Fault?!
    By r07f1 in forum Newbie
    Replies: 2
    Last Post: 11th April 2008, 16:10
  4. Segmentation Fault
    By merry in forum General Programming
    Replies: 4
    Last Post: 12th March 2007, 05:08
  5. segmentation fault
    By shamik in forum Qt Programming
    Replies: 3
    Last Post: 24th November 2006, 08:33

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.