windows Qt/C++ 退出,代码为 -1073741819(程序崩溃,异常代码为 c0000005)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4140207/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Qt/C++ Exited with code -1073741819 (Program crashes with exception code c0000005)
提问by Joseph
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:
我的程序崩溃时遇到了麻烦。我收到“Program.exe 已停止工作”窗口弹出窗口,其中提到我的异常代码是 c0000005。当我从 Qt 中的应用程序返回输出时,它显示:
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.
它位于我的类的构造函数中,wndChildWhatever
它是一个 QMainWindow。newDb
在构造函数参数中定义为DatabaseManager *newDb
并且db
是定义为 的 wndChild 的私有成员DatabaseManager *db
。这个数据库地址在我的程序中到处传递,这wndChildWhatever
是我唯一遇到问题的地址。
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 and 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!
我真的不确定这里发生了什么,希望有人能提供帮助!
回答by asveikau
The faulting line:
故障线路:
db=newDb;
And you say:
你说:
and db is a private member of wndChild
并且 db 是 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.)
听起来您的this
指针可能无效。也就是说,如果这种情况发生在foo
您正在执行的方法中wndChild->foo()
并且wndChild
是无效指针。因此,当它访问db
相对于wndChild
您的偏移量时,会遇到访问冲突。(NT 错误代码0xc0000005
,Windows 表示错误的指针取消引用。)
回答by Jeremy Friesner
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?
很可能不是 db=newDb 行本身导致崩溃,而是稍后执行的一些其他代码,如果您不设置 db 值,则不会执行。查看 wndChildWhatever 类中的其他代码,看看它对 (db) 值做了什么。也许它正在做一些顽皮的事情,比如在其他代码仍在使用它时删除它?
回答by hmuelner
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.
使用 db=newDb 行,您有两个指向同一个对象的指针。你在析构函数中做什么?如果你有“delete db”和“delete newDb”,你会删除同一个对象两次,这可能会导致崩溃或不崩溃。
回答by Reynaldo Silva E Silva
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.
尝试删除构建目录并重建它。它对我有用,但每次我向任何类添加新函数或成员时我都需要这样做。知道为什么。