If you build C/C++ IDA Plugins with Qt you might have ran into this crash:


It was my alternate solution there to do the:

#undef QStringLiteral 
#define QStringLiteral(_str) _str

thing, which works okay when you use ASCII, or wide char text (the Windows L”String” macro) because the compiler will find a constructor for it (that internally calls a translator like the QString::toLatin1() method).

Problem with this though you have to paste this this macro in the right place(s) to make sure it overrides the default macro in the Qt “qstring.h” header.

After studying the header again I found a better way.  Just define QT_NO_UNICODE_LITERAL in the project Visual Studio “Preprocessor” settings making it globally defined.

Doing so will end up with QStringLiteral the macro defined as:
#define QStringLiteral(str) QString::fromUtf8("" str "", sizeof(str) - 1)

This works fine since ASCII text is UTF-8 (with out the extended code points).  And it’s probably not that much different performance-wise from the internal QString::toLatin1() calls et al.

Also just to double check the QT_NO_UNICODE_LITERAL is defined, I add to my “StdAfx.h”:

// QT_NO_UNICODE_LITERAL must be defined (best in preprocessor setting) 
// So Qt doesn't a static string pool that will cause IDA to crash on unload 
    #error QT_NO_UNICODE_LITERAL must be defined to avoid Qt string crashes 


Leave a Reply