Mitch Mitch - 1 month ago 8x
C++ Question

Breaking on assertions with CDB in Qt Creator

Every now and then I get an assertion in

[]. I'm unable to break on this assertion.

I've tried all of the suggestions in this answer, and they either don't work, or are not what I'm after:

You can install a handler for the messages/warnings that Qt emits, and do your own processing of them.

I would rather not have to do this each time it happens.

in qt Creator go to Tools -> Options -> Debugger -> GDB and select "Stop when a qFatal is issued"

This option doesn't exist for CDB.

I have coded a BreakInDebugger function by hand and an assert macro that calls the function.

I don't want to have to touch Qt code. Besides, I could also just edit
and add a line that I can actually break on:

if (i >= 0 && i < d->size)
qDebug() << "oops";

Is this possible using only Creator?

Update: It seems to be related to where the assertion is triggered from. An example like this works:

#include <QGuiApplication>
#include <QtQuick>

int main(int argc, char *argv[])
QGuiApplication app(argc, argv);

QVector<int> i;
i[0] = 0;

QQmlApplicationEngine engine;

return app.exec();

That is, I get the typical error dialog with options to debug the assertion:

Microsoft Visual C++ Runtime Library
Debug Error!

Program: C:\dev\qt5-dev-debug\qtbase\lib\Qt5Cored.dll
Module: 5.8.0
File: C:\dev\qt5-dev\qtbase\src\corelib\global\qglobal.cpp
Line: 3045

ASSERT failure in QVector<T>::operator[]: "index out of range", file c:\dev\qt5-dev-debug\qtbase\include\qtcore\../../../../qt5-dev/qtbase/src/corelib/tools/qvector.h, line 433

(Press Retry to debug the application)

Abort Retry Ignore

However, with a unit test project, I don't get any dialog:

#include <QString>
#include <QtTest>

class Untitled3Test : public QObject


private Q_SLOTS:
void testCase1();


void Untitled3Test::testCase1()
QVector<int> i;
i[0] = 0;


#include "tst_untitled3test.moc"


As discovered in the bug report, this is due to testlib's use of a crash handler that disables the error dialog that usually occurs with assertions. Passing the following application argument to the auto test solves the issue:


This change improves the documentation for this feature.