Results 1 to 4 of 4

Thread: Really strange segmentation fault

  1. #1
    Join Date
    Oct 2009
    Posts
    18
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Really strange segmentation fault

    I get a really strange segmentation fault and I've got no idea why I keep getting it.

    If I would strip down the code (and move everything from .cpp file to .h file) , all that would remain is
    Qt Code:
    1. class App:public QObject{
    2. Q_OBJECT
    3. public:
    4. App(){}
    5. void foo(){m_authenticated = false;}
    6. private:
    7. bool m_authenticated;
    8. }
    To copy to clipboard, switch view to plain text mode 

    (it is too much code to post here so I hope this will be enough, else I will put the code on the net somewhere to download)

    Now the problem is that the call to foo gives me a segmentation fault exactly when I try to access m_authenticated. I have no clue why. Do you? (I've tried the same thing with an int, and it fails. it also fails if it is declared public).

    Any guesses or suggestions on how to debug?

  2. #2
    Join Date
    Oct 2009
    Posts
    18
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Really strange segmentation fault

    When I ran the debugger and added a watch it said: not in scope (when I was inside of foo())!

  3. #3
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 163 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Really strange segmentation fault

    Check that the object you call foo() upon is valid (i.e. esp not the 0-pointer).
    Or: Your error is somewhere else; C/C++ has the nice property that you can overwrite any memory, including the stack, so the debugger's stack trace might be damaged, too.

    (The information, meaning source, you provide, is not enough to track the error down.)

  4. #4
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Really strange segmentation fault

    How do you call foo? You've pasted just the class definition.

Similar Threads

  1. why is there so strange "Segmentation fault" ?
    By lanmanck in forum Qt Programming
    Replies: 9
    Last Post: 2nd March 2010, 12:55
  2. Strange segmentation fault
    By Lykurg in forum Qt Programming
    Replies: 3
    Last Post: 4th January 2009, 19:50
  3. segmentation fault
    By uchennaanyanwu in forum Newbie
    Replies: 3
    Last Post: 31st July 2008, 16:52
  4. Segmentation Fault?!
    By r07f1 in forum Newbie
    Replies: 2
    Last Post: 11th April 2008, 15:10
  5. segmentation fault
    By mattia in forum Newbie
    Replies: 22
    Last Post: 7th November 2007, 10:37

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
  •  
Qt is a trademark of The Qt Company.