
Originally Posted by
TMan
I don't know whether qDebug is thread safe. However, I do know that you can instruct it to write to a file without using qInstallMessageHandler. See docs for QDebug.
this part I got:
here's an excerpt:
#ifndef QT_NO_DEBUG_OUTPUT
static void logOutput(QtMsgType type, const char *msg)
{
QString debugdate
= QDateTime::currentDateTime().
toString("yyyy.MM.dd|hh:mm:ss");
// extract the priority of the message
int priority = message.left(1).toInt();
if (priority >= 0) message.remove(0, 1);
switch (type)
{
case QtDebugMsg:
debugdate += ":";
(*out) << debugdate << " " << message << endl;
break;
case QtWarningMsg:
debugdate += ":";
(*out) << debugdate << " " << msg << endl;
break;
case QtCriticalMsg:
debugdate += ":";
(*out) << debugdate << " " << msg << endl;
break;
case QtFatalMsg:
debugdate += "[F]";
(*out) << debugdate << " " << msg << endl;
}
if (QtFatalMsg == type)
{
abort();
}
}
#endif
#ifndef QT_NO_DEBUG_OUTPUT
QTextStream *out = 0;
QMutex mutex;
static void logOutput(QtMsgType type, const char *msg)
{
QMutexLocker locker(&mutex);
QString debugdate = QDateTime::currentDateTime().toString("yyyy.MM.dd|hh:mm:ss");
QString message(msg);
// extract the priority of the message
int priority = message.left(1).toInt();
if (priority >= 0) message.remove(0, 1);
switch (type)
{
case QtDebugMsg:
debugdate += ":";
(*out) << debugdate << " " << message << endl;
break;
case QtWarningMsg:
debugdate += ":";
(*out) << debugdate << " " << msg << endl;
break;
case QtCriticalMsg:
debugdate += ":";
(*out) << debugdate << " " << msg << endl;
break;
case QtFatalMsg:
debugdate += "[F]";
(*out) << debugdate << " " << msg << endl;
}
if (QtFatalMsg == type)
{
abort();
}
}
#endif
To copy to clipboard, switch view to plain text mode
but do I need to protect the write to the file?
Bookmarks