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.

4
  • 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) Commented Mar 18, 2014 at 16:13
  • as you can see my code is very simple Commented Mar 18, 2014 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 qt.gitorious.org/qt/qt/source/… 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") Commented Mar 18, 2014 at 23:31
  • could you add you version of qt & the compiler version; I suggest you check the preprocessor output (see stackoverflow.com/questions/4493293/… on how to get it) Commented Mar 18, 2014 at 23:43

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

3 Comments

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, ...
Then don't step into it?? If you tell the debugger to step into something, it will. That's why it has Step Over....
I want to step directly into the display function, not into the qstring details, but it seems that it is not possible.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.