PDA

View Full Version : qDebug() 's issue



lutins
1st September 2008, 09:16
im chinese,so where i use qDebug() found a issue.qDebug() can't not output a chinese character in Winxp.
i follow this bug in qcoreapplication_win.cpp in corelib folder function qWinMsgHandler


Q_CORE_EXPORT void qWinMsgHandler(QtMsgType t, const char* str)
{
Q_UNUSED(t);
// OutputDebugString is not threadsafe.

// cannot use QMutex here, because qWarning()s in the QMutex
// implementation may cause this function to recurse
static QWinMsgHandlerCriticalSection staticCriticalSection;

if (!str)
str = "(null)";

staticCriticalSection.lock();
QT_WA({
QString s(QString::fromLatin1(str));
s += QLatin1String("\n");
OutputDebugStringW((TCHAR*)s.utf16());
}, {
QByteArray s(str);
s += "\n";
OutputDebugStringA(s.data());
})
staticCriticalSection.unlock();
}


bug in QString s(QString::fromLatin1(str)); if str is a gb18030 codec.then will get a error code

spirit
1st September 2008, 09:40
try to set needed codec for c-strings usgin this method:


...
int main(int argc, char **argv)
{
...
QTextCodec::setCodecForCStrings(QTextCodec::codecF orName(....));
...
}