Reputation: 11780
When debugging with Qt Creator, each time I step into a method with a QString as parameter I reach some annoying qstring.h code:
// ASCII compatibility
#ifndef QT_NO_CAST_FROM_ASCII
inline QT_ASCII_CAST_WARN QString(const char *ch)
: d(fromAscii_helper(ch, ch ? int(strlen(ch)) : -1))
{}
Is there a way to avoid the debugger to step into qstring.h?
My pro file:
QT += core
QT -= gui
TARGET = ConsoleTest03
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
My code:
#include <QDebug>
#include <QString>
void display(QString s)
{
qDebug() << s;
}
int main(int argc, char *argv[])
{
display("coucou");
return 0;
}
I use Qt 5.1.1 and Qt 3.0.1.
Upvotes: 4
Views: 801
Reputation: 1779
You get there because you are calling that constructor in your code.
display("coucou");
that actually calls
display(QString("coucou"));
and QString(const char*) is not something you really should be doing away. http://qt-project.org/doc/qt-5/qstring.html#QString-8.
You can disable stepping into the constructor by not calling it on that line
QString str(QLatin1String("coucou")); // you don't really need QLatin1String
// if you are happy with 'const char*' constructor
display(str);
And now, you no longer get QString constructor on the display() line. Alternatively, make a breakpoint on display() function and instead of Step In, do a Continue.
You are also calling QString copy constructor because your function takes a QString, not a reference or pointer to the actual object. This should be very easy to spot this in a debugger instead of calling it "annoying". So, here's some code that is guaranteed to let you step into display() without anything else,
#include <QDebug>
#include <QString>
void display(const QString &s)
{
qDebug() << s;
}
int main(int argc, char *argv[])
{
QString str(QLatin1String("foo"));
display(str);
return 0;
}
I hope this is now very, very clear.
Upvotes: 1