[LyX/master] Fix Qt6 deprecation warning (QString::fromUcs4(uint))

Enrico Forestieri forenr at lyx.org
Sun Mar 21 15:56:45 UTC 2021


On Sun, Mar 21, 2021 at 04:48:15PM +0100, Enrico Forestieri wrote:
> On Sun, Mar 21, 2021 at 12:33:12PM +0100, Juergen Spitzmueller wrote:
> > commit 52dff70641788cdd99ca40cf30550861555191c3
> > Author: Juergen Spitzmueller <spitz at lyx.org>
> > Date:   Sun Mar 21 12:38:47 2021 +0100
> > 
> >     Fix Qt6 deprecation warning (QString::fromUcs4(uint))
> 
> Note that this is wrong on systems where the size of wchar_t is 2 bytes.
> If wchar_t is 4 bytes, the argument of those functions is interpreted as
> UCS-4, but if wchar_t is 2 bytes it is interpreted as UTF-16.

On Windows it doesn't even compile:

  CXX      qstring_helpers.o
../../../src/support/qstring_helpers.cpp: In function ‘QString lyx::toqstr(const docstring&)’:
../../../src/support/qstring_helpers.cpp:51:33: error: cannot convert ‘const docstring’ {aka ‘const std::__cxx11::basic_string<unsigned int, std::char_traits<unsigned int>, std::allocator<unsigned int> >’} to ‘const wstring&’ {aka ‘const std::__cxx11::basic_string<wchar_t>&’}
   51 |  return QString::fromStdWString(ucs4);
      |                                 ^~~~
      |                                 |
      |                                 const docstring {aka const std::__cxx11::basic_string<unsigned int, std::char_traits<unsigned int>, std::allocator<unsigned int> >}
In file included from /c/MinGW/Qt/6.0.2/include/QtCore5Compat/qregexp.h:48,
                 from /c/MinGW/Qt/6.0.2/include/QtCore5Compat/QRegExp:1,
                 from ../../../src/support/qstring_helpers.cpp:21:
/c/MinGW/Qt/6.0.2/include/QtCore/qstring.h:1429:60: note:   initializing argument 1 of ‘static QString QString::fromStdWString(const wstring&)’
 1429 | inline QString QString::fromStdWString(const std::wstring &s)
      |                                        ~~~~~~~~~~~~~~~~~~~~^
../../../src/support/qstring_helpers.cpp: In function ‘QString lyx::toqstr(lyx::char_type)’:
../../../src/support/qstring_helpers.cpp:60:33: error: cannot convert ‘lyx::char_type*’ {aka ‘unsigned int*’} to ‘const wchar_t*’
   60 |  return QString::fromWCharArray(&ucs4, 1);
      |                                 ^~~~~
      |                                 |
      |                                 lyx::char_type* {aka unsigned int*}
In file included from /c/MinGW/Qt/6.0.2/include/QtCore5Compat/qregexp.h:48,
                 from /c/MinGW/Qt/6.0.2/include/QtCore5Compat/QRegExp:1,
                 from ../../../src/support/qstring_helpers.cpp:21:
/c/MinGW/Qt/6.0.2/include/QtCore/qstring.h:1259:55: note:   initializing argument 1 of ‘static QString QString::fromWCharArray(const wchar_t*, qsizetype)’
 1259 | inline QString QString::fromWCharArray(const wchar_t *string, qsizetype size)
      |                                        ~~~~~~~~~~~~~~~^~~~~~
make[5]: *** [Makefile:944: qstring_helpers.o] Error 1

-- 
Enrico


More information about the lyx-devel mailing list