Here we can handle we can print different kind of message in file. For example QtDebugMsg, QtWarningMsg etc. We can constantly open a file and print to it and close it. Or we can open it in constructor of a class and flush/close in the destructor of the class. If we want to execute the application and want to get the debug information out then the first one is better (since file will be released). If we want to see the debug information after closing the app then second one should be OK.
void debugOutput(QtMsgType type, const char *msg)
{
QFile debugfile("C:\\Data\\debug.txt");
Q_ASSERT(debugfile.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Append));
switch (type)
{
case QtDebugMsg:
{
QTextStream out(&debugfile);
out << msg;
}
break;
default :
break;
}
debugfile.flush();
debugfile.close();
}
#define TRACE_FUNC_ENTRY qDebug()<< __PRETTY_FUNCTION__ << ">" << endl ;
#define TRACE_FUNC_EXIT qDebug()<< __PRETTY_FUNCTION__ << "<" << endl ;