简体   繁体   English

将 QByteArray 转换为 QString

[英]Convert QByteArray to QString

I want to encrypt the data of a database and to do this, I used AES_128 in this link for encryption.我想加密数据库的数据,为此,我在此链接中使用 AES_128 进行加密。

The result of encryption is a QByteArray and the QByteArray is saved on the text file in the correct shape and I could decode it correctly, but and I need to convert it to the QString and reverse to QByteArray to store and read it on the Sqlite DB.加密的结果是一个 QByteArray 并且 QByteArray 以正确的形状保存在文本文件中,我可以正确解码它,但是我需要将它转换为 QString 并反转为 QByteArray 以在 Sqlite DB 上存储和读取它. I tried some options like我尝试了一些选项,例如

QByteArray encodedText; QString DataAsString = QString(encodedText);

and

string DataAsString1 = encodedText.toStdString();

and

QString DataAsString = QTextCodec::codecForName("UTF-8") >toUnicode(encodedText);

and other solutions like this link , but the outputs of these options aren't in the correct way.和其他类似此链接的解决方案,但这些选项的输出方式不正确。 Because after casting, I couldn't convert the encoded text to decoded correctly.因为投射后,我无法将编码文本转换为正确解码。

This is the input string of encoded text: "\x14r\xF7""6#\xFE\xDB\xF0""D\x1B\xB5\x10\xEDx\xE1""F" and these are the outputs for the different options: \024r�6#���D\033�\020�x�F and \024r�6#���D\033�\020�x�F这是编码文本的输入字符串:"\x14r\xF7""6#\xFE\xDB\xF0""D\x1B\xB5\x10\xEDx\xE1""F" 这些是不同选项的输出: \024r�6#����D\033�\020�x�F 和 \024r�6#���D\033�\020�x�F

Does anybody suggestion about the right conversion?有人建议正确的转换吗?

try to use this: QString QString::fromUtf8(const QByteArray &str)尝试使用这个: QString QString::fromUtf8(const QByteArray &str)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM