Results 1 to 12 of 12

Thread: Why is my program segfaulting?

  1. #1
    Join Date
    Aug 2006
    Posts
    163
    Thanks
    12
    Thanked 5 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Why is my program segfaulting?

    I can't figure out this one. It was working, and then I decided to refactor it and everthing went all pear-shaped

    First, the code :

    /edit : code attached below.
    Last edited by Valheru; 30th September 2006 at 23:54.

  2. #2
    Join Date
    Aug 2006
    Posts
    163
    Thanks
    12
    Thanked 5 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Why is my program segfaulting?

    The code under Server::addServerTab used to be in ServerList::fetchGroupsSlot(). Then I moved it to the Server class, and now it segfaults. It segfaults on the line

    Qt Code:
    1. mw->getServerTabWidget()->addTab( newServerWidget, name );
    To copy to clipboard, switch view to plain text mode 
    Which seems to indicate that it SwatMw *mw isn't initialized, but it gets initialzed in the constructor which is very confusing. What's going on here?
    Last edited by Valheru; 30th September 2006 at 23:55.

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Why is my program segfaulting?

    I'm sorry, I don't want to be rude, but... do you expect us to read and understand 600 lines of code? What do you expect us to do with it? Couldn't you have pasted it as an attachment instead of displaying them inside posts? Is it really necessary to have all the 600 lines to find the problem? I doubt so...

    Did you use a debugger? If not, use one (gdb?) and when the application crashes, check the backtrace (bt) and print values of mw, newServerWidget and mw->getServerTabWidget(). One of them will probably be NULL. Also the backtrace will tell you exactly which functions were called and in what order. Maybe you'll notice something weird. Remember to compile your application in debug mode before feeding it to the debugger.

  4. #4
    Join Date
    Aug 2006
    Posts
    163
    Thanks
    12
    Thanked 5 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Why is my program segfaulting?

    Well, I didn't think about attatching it to be honest. And what difference does it make as to weather or not I attatch it or inline it if you think that 600 lines is too much in the first place? I gave all the code as I wanted to be complete. Sorry if that made your life unbearable

    I also think it's rather gay of you to lambaste me in the thread as well as PM'ing me about it BTW.

    I can't sodding debug it because I'm using Arch Linux (switched from Gentoo because my KDE borked) and Qt isn't compiled with debug flags on Arch.

    I'll see what I can come up with. I was hoping that maybe someone would spot something glaringly wrong wit hmy code - often after staring at your code for hours on end you tend to miss simple things.

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Why is my program segfaulting?

    Quote Originally Posted by Valheru View Post
    And what difference does it make as to weather or not I attatch it or inline it if you think that 600 lines is too much in the first place?
    Because I can ignore/grep/delete/print/do_whatever_I_want if it is attached and I have to scroll through all of it if it is inline. That's simply flooding, especially if you make 4 posts out of it when 1 would be enough.

    I gave all the code as I wanted to be complete.
    There is nothing wrong with it.... as long as you attach it.
    Sorry if that made your life unbearable
    Oh come on! I'm just trying to keep order here.

    I also think it's rather gay of you to lambaste me in the thread as well as PM'ing me about it BTW.
    Very strong words, you should speak them carefully. The PM was a result of an infraction you were given, just a side effect you might say, explaining what you should do to correct the situation (which you haven't done yet anyway).

    I can't sodding debug it because I'm using Arch Linux (switched from Gentoo because my KDE borked) and Qt isn't compiled with debug flags on Arch.
    Hmm... you might try to print those values directly in the application then, without using a debugger. You'll lose the backtrace ability, but if you're right about the place where it crashes (although it probably crashes somewhere inside Qt library), this might be enough.

    I was hoping that maybe someone would spot something glaringly wrong wit hmy code
    In 600 lines? My only guess when looking at your code was that if indeed "mw" was null/garbage then maybe because your constructor was invoked with an incorrect parameter (SwatMw* m I think). But it's only a wild guess - debugger helps in such situations, maybe you should consider rebuilding Qt in debug mode.

  6. #6
    Join Date
    Aug 2006
    Posts
    163
    Thanks
    12
    Thanked 5 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Why is my program segfaulting?

    Well, here are the files as attatchments. I was trying to edit my original posts but apparantly I can't attach files to edits.

    I'm busy installing a debug version of Qt as we speak, it's going to take a while though since I am compiling it from source. I'd hoped I was finished with compiling Qt when I switched from Gentoo but apparently not.

    Thanks for any/all help.

    P.S. You can delete the superflous posts if you want, I can't it seems.
    Attached Files Attached Files

  7. #7
    Join Date
    Aug 2006
    Posts
    163
    Thanks
    12
    Thanked 5 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Why is my program segfaulting?

    Hmm, when I add mw in the class Server as a watch then it resolves to 0x0 which is plainly _WRONG_...although I can't possibly see how that can be since it is passed to the constructor from ServerList when it is added to the QList. And in ServerList it is initialized before that happens, so it should be right. Something is rotten in the state of Denmark...

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Why is my program segfaulting?

    Quote Originally Posted by Valheru View Post
    it resolves to 0x0 which is plainly _WRONG_...although I can't possibly see how that can be since it is passed to the constructor from ServerList when it is added to the QList.
    Then check whether you really pass a valid pointer to the constructor.

    Qt Code:
    1. delete menu, model, connectToServer, newServer, editServer, deleteServer, separator;
    To copy to clipboard, switch view to plain text mode 
    Are you sure that this statement deletes all of these objects?

  9. #9
    Join Date
    Aug 2006
    Posts
    163
    Thanks
    12
    Thanked 5 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Why is my program segfaulting?

    I found the problem. It had to do with the order in which things were happening - mw was being passed as an object parameter before it was being initialized.

    Quote Originally Posted by jacek View Post
    Qt Code:
    1. delete menu, model, connectToServer, newServer, editServer, deleteServer, separator;
    To copy to clipboard, switch view to plain text mode 
    Are you sure that this statement deletes all of these objects?

    I take it that you are trying to tell me that the delete command doesn't work this way?

  10. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Why is my program segfaulting?

    Quote Originally Posted by Valheru View Post
    I take it that you are trying to tell me that the delete command doesn't work this way?
    Delete does not have anything to do with this. It is the "," (comma) operator which is responsible. It groups statements, not arguments.

    http://msdn2.microsoft.com/en-us/library/zs06xbxh.aspx
    http://www.cplusplus.com/doc/tutorial/operators.html (scroll down to "comma operator")

  11. The following user says thank you to wysota for this useful post:

    Valheru (1st October 2006)

  12. #11
    Join Date
    Aug 2006
    Posts
    163
    Thanks
    12
    Thanked 5 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Why is my program segfaulting?

    Thanks, I've changed it so that each pointer is deleted seperately. Am I correct in thinking that you could put the pointers in a list and call delete on the list, like so :

    Qt Code:
    1. delete {pointer_1, pointer_2,...,pointer_n};
    To copy to clipboard, switch view to plain text mode 

  13. #12
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Why is my program segfaulting?

    No, you would try to delete the list object. But you can put all pointers into the list and call
    Qt Code:
    1. qDeleteAll(list);
    To copy to clipboard, switch view to plain text mode 
    or
    Qt Code:
    1. for(int i=0;i<list.size();i++) delete list[i];
    To copy to clipboard, switch view to plain text mode 

  14. The following user says thank you to wysota for this useful post:

    Valheru (1st October 2006)

Similar Threads

  1. program exits
    By ldsjohn in forum Qt Programming
    Replies: 2
    Last Post: 20th September 2006, 19:03
  2. how to embed an existing kde program into Konquerer
    By sephiroth_0 in forum KDE Forum
    Replies: 1
    Last Post: 15th August 2006, 12:21
  3. Release my simple program to other users ?
    By probine in forum Qt Programming
    Replies: 9
    Last Post: 9th July 2006, 23:42
  4. preparing program for release
    By impeteperry in forum Installation and Deployment
    Replies: 5
    Last Post: 22nd April 2006, 19:30
  5. Enter key causing program to exit
    By welby in forum Qt Programming
    Replies: 2
    Last Post: 9th March 2006, 16:11

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.