在Qt Creator中打破CDB的断言
Breaking on assertions with CDB in Qt Creator
我时不时地在 QVector::operator
[] 中得到一个断言。我无法打破这个断言。
我已经尝试了此答案中的所有建议,但它们要么不起作用,要么不是我想要的:
您可以为Qt发出的消息/警告安装处理程序,并自行处理它们。
我宁愿不必每次都这样做。
在 qt 中创建器中转到工具 -> 选项 -> 调试器 -> GDB,然后选择"发出 qFatal 时停止"
国开行不存在此选项。
我已经手动编写了一个 BreakInDebugger 函数和一个调用该函数的断言宏。
我不想碰Qt代码。此外,我还可以编辑qvector.h
并添加一行我实际上可以中断的行:
if (i >= 0 && i < d->size)
qDebug() << "oops";
仅使用造物主可以做到这一点吗?
更新:它似乎与断言的触发位置有关。像这样的例子有效:
#include <QGuiApplication>
#include <QtQuick>
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
QVector<int> i;
i[0] = 0;
QQmlApplicationEngine engine;
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
return app.exec();
}
也就是说,我得到了典型的错误对话框,其中包含用于调试断言的选项:
---------------------------
Microsoft Visual C++ Runtime Library
---------------------------
Debug Error!
Program: C:devqt5-dev-debugqtbaselibQt5Cored.dll
Module: 5.8.0
File: C:devqt5-devqtbasesrccorelibglobalqglobal.cpp
Line: 3045
ASSERT failure in QVector<T>::operator[]: "index out of range", file c:devqt5-dev-debugqtbaseincludeqtcore../../../../qt5-dev/qtbase/src/corelib/tools/qvector.h, line 433
(Press Retry to debug the application)
---------------------------
Abort Retry Ignore
---------------------------
但是,对于单元测试项目,我没有得到任何对话框:
#include <QString>
#include <QtTest>
class Untitled3Test : public QObject
{
Q_OBJECT
public:
Untitled3Test();
private Q_SLOTS:
void testCase1();
};
Untitled3Test::Untitled3Test()
{
}
void Untitled3Test::testCase1()
{
QVector<int> i;
i[0] = 0;
}
QTEST_APPLESS_MAIN(Untitled3Test)
#include "tst_untitled3test.moc"
正如错误报告中发现的那样,这是由于 testlib 使用了崩溃处理程序,该处理程序禁用了通常与断言一起发生的错误对话框。将以下应用程序参数传递给自动测试可解决此问题:
-nocrashhandler
此更改改进了此功能的文档。
相关文章:
- 尝试使用 std::vector<std::thread时出现静态断言失败错误>
- uint_not_usable_without_attribute在业力规则中使用数字生成器时静态断言失败
- C++ 使用增强正则表达式库时断言崩溃
- 从 exe 文件 (Visual Studio ) 启动时调试断言失败
- 如何将向量断言到特征矩阵
- OpenCV - Python 断言错误:SAD 算法 - 立体相机视差图计算
- 使用 Google Test 对自定义断言函数进行单元测试
- 断言"id < 0"在Qt ActiveX中失败
- 初始值设定项列表构造和静态断言
- 在 CppUnit 中测试中止断言失败
- 使用扫描的调试断言失败
- MS 本机单元测试 - 断言::线程失败不起作用
- 如何断言 CRTP 的函数为最终函数?
- 迭代器跳闸视觉C++ 2017 断言
- 如何在 google test in windows 中管理断言
- 为什么我的Qt程序在断言失败后继续运行?
- 在C++中禁用断言宏
- 宏"断言"会在 C++20 中删除吗?
- 在 constexpr 函数中断言
- 在Qt Creator中打破CDB的断言