Qt/C++ Exited with code -1073741819 (Program crashes with exception code c0000005)
I'm having trouble with my program crashing. I get that "Program.exe has stopped working" windows pop-up which mentions my exception code is c0000005. When I return to the output from the application in Qt, it shows:
C:\Users\Me\Desktop\project\project-build-desktop\debug\project.exe exited with code -1073741819
I've found the line that's causing the error (I think!), though I don't know why it might. If I comment out this line, the program won't crash.
The line is:
db=newDb;
This is located in the constructor of my class wndChildWhatever
which is a QMainWindow. newDb
is defined in the constructor arguments as DatabaseManager *newDb
and db
is a private member of wndChild defined as DatabaseManager *db
. This database address is passed around all over my program, and this wndChildWhatever
is the only one I'm having trouble with.
The exception/crash doesn't occur when the window is opened/constructed, however. It happens when the window is closed. What's weirder is that it doesn't happen every time. Sometimes you can open the window a开发者_开发技巧nd close it with out problem, then open it again and on the second closing, it crashes. Other times it happens the first time you try to close it.
I'm really not sure what's going on here and hope someone can assist!
The faulting line:
db=newDb;
And you say:
and db is a private member of wndChild
It sounds like your this
pointer might be invalid. That is, if this happens in a method foo
you are doing something like wndChild->foo()
and wndChild
is an invalid pointer. Therefore when it access the offset of db
relative to wndChild
you hit an accesses violation. (NT error code 0xc0000005
, Windows-speak for a bad pointer dereference.)
Most likely it's not the db=newDb line itself that's causing the crash, but rather some other code that gets executed later on, that doesn't get executed if you don't set the db value. Have a look at the other code inside your wndChildWhatever class, and see what it is doing with the (db) value. Perhaps it is doing something naughty, like deleting it while other code is still using it?
With the line db=newDb you have two pointers to the same object. What do you do in the destructors? If you have "delete db" and "delete newDb" you delete the same object twice which may lead to a crash or not.
Try to delete the build directory and rebuild it. It worked for me, but i need to do it everytime I add a new function or member to any class. Idk why.
精彩评论