QT - 如何将文件名编码设置为西里尔文

时间:2017-02-24 17:16:49

标签: c++ qt file encoding

创建名为“абцде”的文件时 文件名是用象形文字

写的
const QByteArray data = "someData"; // some Data
QString fileName = "абцде.txt"; // fileName
QFile localFile(fileName.toUtf8());
localFile.open(QIODevice::WriteOnly);
localFile.write(data);
localFile.close();

2 个答案:

答案 0 :(得分:1)

这些代码行构成了nternationalization上的qt man 可以帮助。 (QString最初使用Unicode)。

/**
 * Represents an asynchronous operation.
 *
 * @param <T> the type of the result of the operation
 * @deprecated {@code Task} has been deprecated in favor of
 *     <a href="https://googleapis.github.io/api-common-java/1.1.0/apidocs/com/google/api/core/ApiFuture.html">{@code ApiFuture}</a>.
 *     For every method x() that returns a {@code Task<T>}, you should be able to find a
 *     corresponding xAsync() method that returns an {@code ApiFuture<T>}.
 */

您可能需要使用编码(&#34; Windows-1251&#34;),这是一种强力方法。

答案 1 :(得分:0)

如果您的来源是UTF8编码,那么您应该使用此(Qt Documentation

QString fileName = QString::fromUtf8( "абцде.txt" ); // fileName

如果您的来源有其他编码,那么您可以选择其他功能,例如QString::fromLocal8Bit

相关问题