Debugging informations with qDebug()
I need every time test the (return value / return type) of a (method / simple function), the variable type or generally the behaviour of a block of code or anything else ? How can I use the qDebug() function to do this? I prefer a custom function or class that call the qDebug() and that make possible to put out debugging informations in a window attached to my application; like the debugging system but more comprehensible.
Thanks in advance !
I'm not sure I get what you want. qDebug() is just a convenience class the help outputting debugging messages. For easing developers' lives it has some nice formatters for some of Qt's objects. It is not a test and verification framework. For the latter you might want to have a look at the [[Doc:QtTest]] framework, more information on the [[Doc:QTestLib Manual]].
[quote author="freecamellia" date="1320405908"]I prefer a custom function or class that call the qDebug() and that make possible to put out debugging informations in a window attached to my application; like the debugging system but more comprehensible.
Thanks in advance ![/quote]
You are looking for unit testing, or at least the use of assertions. But if you want a system that is going to "observe" your application while it is running you need either a debugger or a logger.
- unit testing = to verify your code is still correct after changes and produces good output for specified input
- debugging = to observe how values and control flows changes in your program
- logging = to trace silently the application
Of course, you can mix the above to get the best result depending on your wills and needs.
I think you need just to write in your code @qDebug()<< value;@
where value denotes the variable which is the return value or the value you want to know. You can look the output of value printed by qDebug in application output tab while the program is running.
You can also use "qInstallMsgHandler()":http://doc.qt.nokia.com/latest/qtglobal.html#qInstallMsgHandler to make qDebug() and friends output to whereever you like.