How to implement "\n" in QT QDebug class
-
I am a fan of having code to debug code ratio of 1:99... Here is my most abused debug code example:
#ifdef MAIN_WINDOW_FLOW
text = " MainWindow_Serial(QWidget *parent) flow CHART ";
//text += "m_currentSettings.name";
//text += m_currentSettings.name;
text += Q_FUNC_INFO;
text += QString::number(__LINE__);
qDebug() << text;
exit(42);
qDebug() << text;
#endifI am using QT and been told that "you cannot use (standard ?? ) printf "escape codes " ( I am not sure about correct term here ...) such as \n or \t ..." I am not interested debating ( in QT forum or here ) why QT cannot do that , however, I like to find another way to instruct QString / QDebug to implement these "make it human readable " codes. Any reasonable C++ hacks would be appreciated. Cheers
-
I am a fan of having code to debug code ratio of 1:99... Here is my most abused debug code example:
#ifdef MAIN_WINDOW_FLOW
text = " MainWindow_Serial(QWidget *parent) flow CHART ";
//text += "m_currentSettings.name";
//text += m_currentSettings.name;
text += Q_FUNC_INFO;
text += QString::number(__LINE__);
qDebug() << text;
exit(42);
qDebug() << text;
#endifI am using QT and been told that "you cannot use (standard ?? ) printf "escape codes " ( I am not sure about correct term here ...) such as \n or \t ..." I am not interested debating ( in QT forum or here ) why QT cannot do that , however, I like to find another way to instruct QString / QDebug to implement these "make it human readable " codes. Any reasonable C++ hacks would be appreciated. Cheers
Have you even looked at the documentation for QDebug? Specifically :
Quote:
QDebug &QDebug::operator<<(QChar t) Writes the character, t, to the stream and returns a reference to the stream. Normally, QDebug prints control characters and non-US-ASCII characters as their C escape sequences or their Unicode value (\u1234). To print non-printable characters without transformation, enable the noquote() functionality, but note that some QDebug backends may not be 8-bit clean and may not be able to represent it.
which leads us to:
Quote:
QDebug &QDebug::noquote() Disables automatic insertion of quotation characters around QChar, QString and QByteArray contents and returns a reference to the stream. When quoting is disabled, these types are printed without quotation characters and without escaping of non-printable characters.
If you need quoted output, its simple enough to do it yourself, just escape the quotes (\") or use Raw literals e.g.
std::string hello(R"x("Hello World")x")
assigns"Hello World"
, *including the quote marks" to the variablehello
, NB. I have not tried this. I do not use QT. I don't know if this will achieve what you want. I do know how to use google, though. It's more than time enough that you did too.Keep Calm and Carry On
-
Have you even looked at the documentation for QDebug? Specifically :
Quote:
QDebug &QDebug::operator<<(QChar t) Writes the character, t, to the stream and returns a reference to the stream. Normally, QDebug prints control characters and non-US-ASCII characters as their C escape sequences or their Unicode value (\u1234). To print non-printable characters without transformation, enable the noquote() functionality, but note that some QDebug backends may not be 8-bit clean and may not be able to represent it.
which leads us to:
Quote:
QDebug &QDebug::noquote() Disables automatic insertion of quotation characters around QChar, QString and QByteArray contents and returns a reference to the stream. When quoting is disabled, these types are printed without quotation characters and without escaping of non-printable characters.
If you need quoted output, its simple enough to do it yourself, just escape the quotes (\") or use Raw literals e.g.
std::string hello(R"x("Hello World")x")
assigns"Hello World"
, *including the quote marks" to the variablehello
, NB. I have not tried this. I do not use QT. I don't know if this will achieve what you want. I do know how to use google, though. It's more than time enough that you did too.Keep Calm and Carry On
I need time to digest and try your approach. PS I would like to pass this TO YOU (only). In past I did appreciate your help and I am little concerned that you have a caught the "I told you so ...RTFM.. everybody knows that..." disease. Please get well soon... cheers
-
I need time to digest and try your approach. PS I would like to pass this TO YOU (only). In past I did appreciate your help and I am little concerned that you have a caught the "I told you so ...RTFM.. everybody knows that..." disease. Please get well soon... cheers