PDA

View Full Version : using qDebug for entry and exit of functions of a single class



sunburns
30th April 2018, 16:51
I'm adding debug messages that print when I enter and exit a function, such as:

void MyClass::function1()
{
qDebug() << "enter";
...
qDebug() << "exit";
}

QString MyClass::function2(QString input_text)
{
qDebug() << "enter " << input_text;
...
qDebug() << "exit return = " << return_value;
}

I set QT_MESSAGE_PATTERN to print the function name and line number. When I compile, I use QT_NO_DEBUG to turn the print statements on and off.

My program is very large, with probably 100 files, each containing a class. I would like a way to turn the debug statement on in a single class, while it is off for all the other classes. Any suggestions?

d_stranz
30th April 2018, 21:01
Sounds like you are writing a program and you don't have confidence in how it works.

I would add the line


#define QT_NO_DEBUG

near the top of each cpp file (not in the header files), and do not add it as a command line compile option. If you want to turn on qDebug() statements for a certain file, comment out that line and rebuild the file.

sunburns
3rd May 2018, 03:00
Thanks. That's just what I need.