简体   繁体   中英

What is missing here in the usage of fromAscii()?

I've some strange issue and don't know how to figure it out.

setup:- Qt4.8.2 and Win7 platform and IDE VS2010.

Lets Assume: A.dll , contains the code snippet described below & B.dll , c.dll etc are other dependent dll's and they together build using a build scripts in build machine(TFS server).There were no problem until today that, we noticed A.dll have some issue in the usage of fromAscii() described below. But, in order to reproduce this error from IDE I couldn't get the same issue ...

Problem statement: fromAscii() , on What it depends on ??

Code snippet:-

char cache[257] = "I just want to save this now here!!!";  // For example I've simplified it here after my analysis.

 QString sStore = Qstring::fromAscii(cache,-1);

"sStore " when printed resulted in nothing..

I feel that some build settings has created this issue. But, couldn't find out the same.Qt description I went on reading and found something like this " Note that, despite the name, this function actually uses the codec defined by QTextCodec::setCodecForCStrings() to convert str to Unicode. Depending on the codec, it may not accept valid US-ASCII (ANSI X3.4-1986) input. If no codec has been set, this function does the same as fromLatin1() ."

So, I want to understand what this actually meant Or what I'm missing here???

For me this works, Qt4.7 Linux :

char buf[ 256 ] = {};
int size;
// copy data to buf no null terminated
// set size, then:
QString().fromAscii((char*)&buf[0], size));

// I'm passing qstring to function

Have you tried passing size yourself?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM