Qt char * to QString [英] Qt char* to QString

查看:196
本文介绍了Qt char * to QString的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将 char * 转换为 QString 。这应该是一个微不足道的任务,但问题是,我有以下输入:

I am trying to convert char* to QString. It should be a trivial task but the problem is, I am having the following input:

item    char [512] "N"  char [512]
    [0] 78 'N'  char
    [1] 0 '\0'  char
    [2] 73 'I'  char
    [3] 0 '\0'  char
    [4] 70 'F'  char
    [5] 0 '\0'  char
    [6] 84 'T'  char
    [7] 0 '\0'  char
    [8] 89 'Y'  char
    [9] 0 '\0'  char
    [10]    0 '\0'  char

注意每个字符'\0'后的空字符。只要尝试转换就会产生字符串N,因为它应该导致字符串NIFTY

Notice the null character after each character '\0'. Simply trying to convert it just yields the string "N" where as it should result into string "NIFTY".

我不知道它是unicode还是Ansi string (事实上我不太了解它)。

I am not sure if it is unicode or Ansi string (in fact I don't know much about it). Can anyone please sort out what is going wrong here or what am I missing?

推荐答案

这适用于我:

    char * chr = "N\0I\0F\0T\0Y\0\0";
    QString str = QString::fromUtf16((ushort*)(chr));
    qDebug() << str;

这篇关于Qt char * to QString的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆