“调试断言失败";从发布模式更改为调试模式时出错

“调试断言失败

问题描述:

我在发布模式下运行了项目,没有问题. 然后我将模式更改为调试模式,并且出现错误调试断言失败".

I ran my project in release mode and I had no problem. and than I changed the mode to debug mode and I have an error "debug assertion failed".

是导致它的代码:

   QXmlStreamReader* xmlReader = new QXmlStreamReader(xmlFile);
   xmlReader->readNextStartElement();

   QXmlStreamAttributes attributes;
   attributes = xmlReader->attributes();
   cout << (attributes.value("name").toString().toStdString());

在此提示行之后,我进行了错误按摩.

After this cout line I had the error massage.

造成差异的模式之间有什么差异?

What can be the difference between the modes that caused the difference?

我想知道在调试模式下运行项目需要做些什么.

I want to know what I need to change for running the project in debug mode.

两种模式之间的差异在于发布模式

The difference between the modes is that in release mode

assert( expr );

编译为空.在调试模式下,它将编译为以下内容:

compiles to nothing. In debug mode it compiles to something like:

if (!(expr))
   assert_failed( "expr" );

(上面是为了说明问题,有些细微之处).这意味着您在发布模式下没有注意到问题(您可能做了类似写一些未使用的内存的操作).墨菲定律说,当您向大客户/教授进行演示时,您会注意到这些问题.

(The above is to give the flavour, there are some subtleties). What this means is that you didn't notice the problems in release mode (you probably did something like write over some unused memory). Murphy's Law says that you will notice the problems when you come to demo to a big customer / your professor.

如果您查看断言所在的行,它将告诉您它在抱怨什么.您需要解决该问题.

If you look at the line where the assertion occurs, it will tell you what it is complaining about. You need to fix that.