QString str;char* ss = str.toAsii().data();
C++ (Qt)const char *ss = qPrintable ( str );char* ss = str.toAsii().data();
C++ (Qt)#define qPrintable(string) (string).toLocal8Bit().constData();
C++ (Qt)const char *func(){ QString str = "......"; return qPrintable( str );}
C++ (Qt)QString str("bla-bla"); const char *ptrStr = str.toLocal8Bit().constData(); //do something with ptrStr
C++ (Qt)int main(int argc, char *argv[]){ QString aaaa = QString("aaaaaBBBB"); const char *astr = qPrintable(aaaa); qDebug("%s",astr); return 0;}
==305== Invalid read of size 1==305== at 0x694EE0E: QString::fromUtf8(char const*, int) (in /usr/lib/libQtCore.so.4.5.0)==305== by 0x6951622: QString::vsprintf(char const*, __va_list_tag*) (in /usr/lib/libQtCore.so.4.5.0)==305== by 0x68FEDC7: qDebug(char const*, ...) (in /usr/lib/libQtCore.so.4.5.0)==305== by 0x40E2E1: main (main.cpp:20)==305== Address 0xbd35a68 is 24 bytes inside a block of size 41 free'd==305== at 0x4C265AF: free (vg_replace_malloc.c:323)==305== by 0x40E2D2: main (main.cpp:19)UUUUUUUUUUUUUUUUU