Deprecated fromUcs4
-
Hi!
Migrating my code to Qt6.2.3, I have the following warning:
warning: 'fromUcs4' is deprecated: Use char32_t overload*
This is triggered by the following lines:static const uint globe_32 = 0x1F30D; //outside QChar(char_16) static const QString u_globe( QString::fromUcs4(&globe_32, 1) ); //🌍
This is driving my nuts, as I've tried many Qt6 ways of declaring my QString and nothing has worked: in the best case I get a unicode char but it is not the one I want (ie it is not interpreted correctly). So, my question is: how are we supposed to initialize a QString from a unicode character defined by its hexadecimal value in Qt6?
Thanks for any hints!
-
The warning mesages says how to fix it - don't use
uint
butchar32_t
as data type as this is the correct one (now that c++ added it in c++11 - so since 10 years or so :) ) -
If I do:
static const char32_t globe_32 = 0x1F30D; //outside QChar(char_16) static const QString u_globe( QChar(globe_32) ); //🌍
I get many warnings warning: unused function 'u_globe' (so it sees the constructor as a function) and at some point the build fails.
If I do
static const char32_t globe_32 = 0x1F30D; //outside QChar(char_16) static const QString u_globe = QString( QChar(globe_32) ); //🌍
I get ASSERT: "rc <= 0xffff" in file /Applications/Qt/6.2.3/macos/lib/QtCore.framework/Headers/qchar.h, line 115 when running.
I've also tried:
static const QString u_globe = QString( QChar::fromUcs4(globe_32) ); //🌍
But then I've got error: no matching conversion for functional-style cast from 'R' to 'QString'
So in the end, I'm blocked, I don't see any other applicable constructors and it all seems very complicated to simply initialize a QString from a UTF char...
-
@MathiasGr said in Deprecated fromUcs4:
static const uint globe_32 = 0x1F30D; //outside QChar(char_16)
static const QString u_globe( QString::fromUcs4(&globe_32, 1) );What's wrong with my comment 'don't use uint but char32_t as data type'?
static const char32_t globe_32 = 0x1F30D; //outside QChar(char_16)
static const QString u_globe( QString::fromUcs4(&globe_32, 1) );