【发布时间】:2017-02-07 17:15:50
【问题描述】:
我在从 QT 下以 Base64 编码的字符串中获取变音符号时遇到问题。我正在创建字符串,然后使用 Base 64 对其进行编码,并将其保存到文件中。接下来我想从打开的文件中解码字符。这是我的做法。
void MainWindow::on_treeWidget_2_doubleClicked(const QModelIndex &index){
encode("([ęśćźół35:11");
decode();
}
void MainWindow::encode(QString input){
QString item_to_change = input.toUtf8().toBase64();
QString filename="output.txt";
QFile file( filename );
if ( file.open(QIODevice::ReadWrite) )
{
QTextStream stream( &file );
stream << encoded;
}
}
void MainWindow::decode(){
QFile input("output.txt");
if (input.open(QIODevice::ReadOnly)) {
data_in = input.readAll();
}
QString strRestored(QByteArray::fromBase64(data_in));
qDebug() << strRestored;
}
这样做我得到的只是 ([esczol35:11 而不是 ([ęśćźół35:11
请帮助我获取开头输入的所有字符。 谢谢
【问题讨论】:
-
如果您在源代码中遇到硬编码字符串的问题,您需要检查在 IDE 中保存 .cpp 文件时使用的编码方式
-
这可能只是字符串文字中字符串编码的产物。您应该始终使用 QStringLiteral 包装您的字符串文字。