unsigned char是无符号字符,代表的范围为0-255,转QString要通过int来牵线,下面直接上代码与图: QString uncharToQstring(unsignedchar* id,intlen) { QString temp,msg;intj =0;while(j<len) { temp= QString("%1").arg((int)id[j],2,16, QLatin1Char('0')); msg.append(temp); j++; }retu...
使用QString::fromUtf8()或其他适合的编码方式将unsigned char*转为QString: 如果数据是以UTF-8编码的,可以使用QString::fromUtf8()方法。如果数据使用其他编码,需要选择相应的QString构造方法或转换函数。 示例代码(假设数据是UTF-8编码的): cpp unsigned char* data = ...; // 指向要转换的数据 int lengt...
//unsiged char *转QString unsigned char *str = "fdd" ; char *str1 = (char *)str; QString str2 = QString(QLatin1String(str1)); //QString 转化成char * QString str = "fdd"; QByteArray ba = str.toLatin1(); unsigned char * str1 = (unsigned char *)ba.data;...
//unsiged char *转QString unsigned char *str = "fdd" ; char *str1 = (char *)str; QString str2 = QString(QLatin1String(str1)); //QString 转化成char * QString str = "fdd"; QByteArray ba = str.toLatin1(); unsigned char * str1 = (unsigned char *)ba.data;分类: Qt 好...
unsigned char* 转qstring,unsignedchar*ch;std::stringstr=(char*)ch;QStringsstr=QString::fromStdString(str);
unsigned char* ch; QString str=""; str=str.append(ch); 或者str+=ch; 你就这样用就可以了,没有问题的,要是真的还有问题就把ch先转成QChar
因为char*最后都有一个‘/0’作为结束符,而采用QString::toLatin1()时会在字符串后面加上‘/0’...
Qt下面,字符串都用QString,确实给开发者提供了方便,想想VC里面定义的各种变量类型,而且函数参数类型五花八门,经常需要今年新那个类型转换 Qt再使用第三方开源库时,由于库的类型基本上都是标准的类型,字符串遇的多的就是Char*类型 在Qt下...
QByteArray byteArray;unsigned char * p = (unsigned char *)byteArray.data();
QString -> char: const QByteArray ba = string.toAscii(); // make ba const, because modifying this array might otherwise invalidate the pointer const char* sequence = ba.constData(); // now sequence will remain valid within the current scope. ...