PDA

View Full Version : QTime deadlocks in my qDebug() custom handler ...



ivrusuboca
9th September 2009, 02:35
Hello Qt guys,

I wrote an MT application and all those threads are using qDebug() for logging their stuff .

I also wrote a custom qDebug() handler, where I wanted to also mark the time when the record is logged :

const QString timeFormat = "HH:mm:ss.zzz";

void myMessageOutput(QtMsgType type, const char *msg) {

const char * time = QTime::currentTime().toString(timeFormat).toStdStr ing().c_str();

switch (type) {
case QtDebugMsg:
fprintf(stdout, "[DEBUG][%s]: %s\n", time, msg);
break;
case QtWarningMsg:
fprintf(stdout, "[WARNING][%s]: %s\n", time, msg);
break;
case QtCriticalMsg:
fprintf(stdout, "[CRITICAL][%s]: %s\n", time, msg);
break;
case QtFatalMsg:
fprintf(stdout, "[FATAL][%s]: %s\n", time, msg);
break;
//abort();
}

fflush(stdout);
}


I have noticed, however, that under very busy usage by these threads, the qDebug() logging locks ( deadlocks maybe ) , and I believe that QTime might be the culprit, because when I remove it from my custom qDebug() handler, all goes very well :

void myMessageOutput(QtMsgType type, const char *msg) {

switch (type) {
case QtDebugMsg:
fprintf(stdout, "[DEBUG]: %s\n", msg);
break;
case QtWarningMsg:
fprintf(stdout, "[WARNING]: %s\n", msg);
break;
case QtCriticalMsg:
fprintf(stdout, "[CRITICAL]: %s\n", msg);
break;
case QtFatalMsg:
fprintf(stdout, "[FATAL]: %s\n", msg);
break;
//abort();
}

fflush(stdout);
}

Would you mind helping me find if there is something wrong with QTimer in an MT environment or it is me who wrote some crap code ?

Oh - yes ; I forgot to mention; when the 'deadlock' occurs, the last 'timestamp' that * time pointer is printing to stdout is some rubbish, suggesting that it either points to some weird address, of the content at the eligible address has been erased.

Thank you,
_iv_