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

QTextCodec::toUnicode() behavior changed

    XMLWordPrintable

Details

    • macOS, Windows
    • fc89bba57 (dev), e70faa7e0 (6.6)

    Description

      Moving from Qt5 to Qt6, QTextCodec::toUnicode() behavior is changed. 

      In Qt6 QTextCodec::codecForName("ISO 8859-1")->toUnicode("",0) returns
      QString()
      but it should return
      QString(0, QChar(0))
      Or in other words it should return of Data::allocate(0) instead of Data::sharedNull()

      Attached example reproduces this. When run example output:

      #Qt5.15: ###

      input:  "" isNull:  no isEmpty:  yes
      input:  "", 0 isNull:  no <–(behavior) isEmpty:  yes
      input:  nullptr isNull:  yes isEmpty:  yes

      #Qt6.5.2: ###

      input:  "" isNull:  no isEmpty:  yes
      input:  "", 0 isNull:  yes <–(different behavior)isEmpty:  yes
      input:  nullptr isNull:  yes isEmpty:  yes

      Expectation is, toUnicode("") and toUnicode("",0) should return the same value and an empty string should stay an empty string no matter which coding is used.

      Update:

      probably fix also needed in qtextcodec.h

      QString toUnicode(const char *in, int length, ConverterState *state = nullptr) const
      {
      if (in == nullptr || length <= 0)
      return {};
      return convertToUnicode(in, length, state);
      }
      QByteArray fromUnicode(const QChar *in, int length, ConverterState *state = nullptr) const
      {
      if (in == nullptr || length <= 0)
      return {};
      return convertFromUnicode(in, length, state);
      } 

      "|| length <= 0" may be removed.

      Attachments

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

        Activity

          People

            vhilshei Volker Hilsheimer
            irfan.omair@digia.com Irfan Omair
            Vladimir Minenko Vladimir Minenko
            Alex Blasche Alex Blasche
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes