Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-100186

QByteArray的函数insert()

    XMLWordPrintable

Details

    • Bug
    • Resolution: Invalid
    • Not Evaluated
    • None
    • 6.3.0 Alpha
    • None

    Description

      //case1:Chinese string, It has an odd number of characters;
      QString text_str="你好吗";//chinese
      QByteArray text_arr=text_str.toUtf8();

      int len=text_arr.length();
      QByteArray test=text_arr.insert(len/2,"\t");

      qDebug()<<"len="<<len;
      qDebug()<<"test="<<test.data();

      //case2:Chinese string, It has an even number of characters;
      QString text_str2="你好的吗";//chinese
      QByteArray text_arr2=text_str2.toUtf8();

      int len2=text_arr2.length();
      QByteArray test2=text_arr2.insert(len2/2,"\n");

      qDebug()<<"len2="<<len2;
      qDebug()<<"test2="<<test2.data();

      /*

      • From the above two cases, we can see that the difference between the two is that the number of Chinese characters is odd (len= odd) and the number of Chinese characters is even (Len2 = even).
        If the number of characters is odd (len= odd), we use QByteArray insert() to find the insert failed because of question marks (garbled characters).
        Only if the number of Chinese characters is even (len2= even) can we successfully insert characters using QByteArray's insert() function.
        I'm not sure if this is a bug.Maybe this function shouldn't be used this way. If so, I'm sorry for the trouble.
        *
      • 通过上面两个案例我们可以看到:两者不同就是中文字符个数一个为奇数(len=奇数),一个为偶数(len2=偶数)。
        当中文字符个数为奇数时(len=奇数),我们用QByteArray的insert()函数插入字符可以发现插入失败,因为有问号(乱码)。
        只有当中文字符个数为偶数时(len2=偶数),我们用QByteArray的insert()函数插入字符才能成功插入。
        我不确定这是否是一个bug。或许这个函数不应该这样使用。如果是的话,很抱歉给你们添麻烦。
        */

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            manordheim Mårten Nordheim
            tmf_18085583045 清风 清风
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes