Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Please help!! Segmentation fault in Qt
Forum Updated to NodeBB v4.3 + New Features

Please help!! Segmentation fault in Qt

Scheduled Pinned Locked Moved General and Desktop
8 Posts 3 Posters 1.8k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jmalicke
    wrote on last edited by
    #1

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

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andreyc
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • J Offline
        J Offline
        jmalicke
        wrote on last edited by
        #3

        Using backtrace gives me:

        0×0 ???????????

        I do not have any suspicious places to look at besides the compiler generated destructor for MainWindow.

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andreyc
          wrote on last edited by
          #4

          If you run app under debugger and step over source code what is last line before the explosion?

          1 Reply Last reply
          0
          • A Offline
            A Offline
            ambershark
            wrote on last edited by
            #5

            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.

            My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

            1 Reply Last reply
            0
            • J Offline
              J Offline
              jmalicke
              wrote on last edited by
              #6

              I see. Valgrind doesn't pick anything up so it's made this problem excruciatingly difficult.

              1 Reply Last reply
              0
              • A Offline
                A Offline
                andreyc
                wrote on last edited by
                #7

                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.

                1 Reply Last reply
                0
                • A Offline
                  A Offline
                  ambershark
                  wrote on last edited by
                  #8

                  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.

                  My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

                  1 Reply Last reply
                  0

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved