我在QT下從Base64編碼的字符串獲取變音符號時遇到問題。我創建字符串,然後我使用Base 64對其進行編碼,然後將其保存到文件中。接下來,我想解碼打開的文件中的字符。這是我如何做到這一點。來自Base64的QT變音字符
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](http://doc.qt.io/qt-5/qstring.html#QStringLiteral)包裝你的字符串文字。 – MrEricSir