4

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?

Edit 1

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;
}

Edit 2

I use Qt 5.1.1 and Qt 3.0.1.

Community
  • 1
  • 1
Martin Delille
  • 11,360
  • 15
  • 65
  • 132
  • Can you add the flags defined in your .pro / your code, please? You may have a #define QT_ASCII_CAST_WARNINGS, which is deprecated, thus triggering the warning) – Armaghast Mar 18 '14 at 16:13
  • as you can see my code is very simple – Martin Delille Mar 18 '14 at 18:57
  • I can't give you a final answer, but I can help a bit: you have a warning, because QT_ASCII_CAST_WARN can expand to nothing (which would cause no issue) or to Q_DECL_DEPRECATED (which is a compiler-specific macro to trigger a warning). See lign 1135 of https://qt.gitorious.org/qt/qt/source/7982a378c7058ca6b1ee29f5f5039cb62d2dcfd5:src/corelib/global/qglobal.h Solution A: undefine QT_ASCII_CAST_WARNINGS before including QString (but I see no reason it's defined in the 1st place) B: Use a method char*->QString like QString::fromUtf8("coucou"); or QStringLiteral("coucou") – Armaghast Mar 18 '14 at 23:31
  • could you add you version of qt & the compiler version; I suggest you check the preprocessor output (see http://stackoverflow.com/questions/4493293/preprocessor-output-on-qt-creator on how to get it) – Armaghast Mar 18 '14 at 23:43

1 Answers1

1

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.

user3427419
  • 1,769
  • 11
  • 15
  • 1
    I understand your point, but with your solution I step into much more unintersting code than before: *qstring.h*, *qglobal.h*, *qrefcount.h*, *qbasicatomic.h*, ... – Martin Delille Mar 19 '14 at 12:37
  • Then don't step into it?? If you tell the debugger to step into something, it will. That's why it has Step Over.... – user3427419 Mar 19 '14 at 15:02
  • 1
    I want to step directly into the display function, not into the qstring details, but it seems that it is not possible. – Martin Delille Mar 20 '14 at 13:50