B
B
BadCats2020-07-05 11:42:41
MySQL
BadCats, 2020-07-05 11:42:41

Full utf8mb4 support in Qt for storing Emoji in MySql table?

Qt parses a file that contains emoji characters. After that, the data is written to a MySql table of type - InnoDB, in an attribute of type varchar. After adding to the table (and in Qt itself when debugging), a part of Emoji, such as:
https://emojipedia.org/drop-of-blood/ https://emojipedia.org/tooth/ - are not displayed
What I already did:
Creating a table specifying attribute encoding:

"CREATE TABLE IF NOT EXISTS `"+tableName+"`(filed1 int not null AUTO_INCREMENT, 
filed2 varchar(30),filed3 varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci,
filed4 varchar(300) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci,filed5 varchar(100),
PRIMARY KEY(filed1),INDEX USING BTREE(filed1)"");"

Setting the encoding for the database:
ALTER DATABASE <имя моей базы> CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

Setting encoding in Qt:
QTextCodec::setCodecForLocale(QTextCodec::codecForName("UTF-8"));

I was told that:
mysql clients, by the way, must also use the utf8mb4 encoding, otherwise emoji will also be lost when transcoding back and forth

Hence, two questions:
1) Judging by the messages of this topic https://stackoverflow.com/questions/25727970/pasti... and according to the debugger - qt captures emoji in the form of escape sequences 55358, 56759, but simply does not display (to me actually, this is not necessary in the editor), but if the characters are present in the line, why are they still written incorrectly to the table?
2) https://bugreports.qt.io/browse/QTBUG-60039?focuse...
-
As you know utf8mb4 is a MySQL define and not a real codec.
- then how can mysql clients use it?
Also, I saw the option that after connecting to the database, you need to execute the first request: How, working with Qt, as with MySql client, to achieve full support for Emoji characters when writing to a table?
SET NAMES ("имя кодировки")

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question