How to
How to

Reputation: 103

QT - How set filename encoding to cyrillic

when creating a file named "абцде" the filename is written with hieroglyphics

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

Upvotes: 1

Views: 1991

Answers (2)

Neyroman
Neyroman

Reputation: 51

These lines of code form qt man on internationalization can help. ( QString use Unicode originally ).

QTextCodec *codec = QTextCodec::codecForName( "Windows-1251" );
QByteArray encodedString = codec->fromUnicode( "абцде.txt" );

You might need to play around with encodings ( "Windows-1251" ), kind of brute force method.

Upvotes: 2

Evgeny
Evgeny

Reputation: 4010

If your sources are UTF8 encoded, then you should use this (Qt Documentation)

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

If your sources has other encoding then you can select other functions like QString::fromLocal8Bit.

Upvotes: 0

Related Questions