[英]QT diacritic characters from Base64
我在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
請幫助我獲取開始時輸入的所有字符。 謝謝
我懷疑問題不在Base64編碼/解碼中,因為這將完全返回您每次輸入的內容。 這就是重點。 我相信您對“ encode”方法的調用正在轉換字符串文字,或者toUtf8錯誤地轉換了字符串文字。 使用qDebug打印出每個步驟,以查看問題所在,然后可能需要查看QTextCodec類以正確設置轉換。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.