How to create non-Unicode file name in Windows like GB18030 encoding
-
Hi All,
I am trying to create GB18030 encoding file name in Windows 7 x64.
I am able to create file content with GB18030 encoding but unable to do the same with file name.Could you please let me know how to do this?
My code:
@
void MainWindow::on_pushButton_34_clicked()
{
QString Afilename = "阿斯的发送gb18030.txt";
QString stringGB18030 = "阿斯的发送gb18030.txt";
QTextCodec *codec = QTextCodec::codecForName("GB18030");
QByteArray encodedStringGB18030 = codec->fromUnicode(stringGB18030);
QString filename = "C:\TEMP_I18N\" + encodedStringGB18030;if (QDir("C:\\TEMP_I18N").exists()) { QFile file(filename); if (file.open(QIODevice::ReadWrite)) { QTextStream stream(&file); stream.setCodec("GB18030"); QString Xstream = QString::fromUtf8("玀玁玂玃玅玆玈玊"); stream << Xstream; ui->lineEdit_3->setText("File " + Afilename + " created at folder C:\\TEMP_I18N"); } } else { QDir().mkdir("C:\\TEMP_I18N"); QFile file(filename); if (file.open(QIODevice::ReadWrite)) { QTextStream stream(&file); stream.setCodec("GB18030"); QString Xstream = QString::fromUtf8("玀玁玂玃玅玆玈玊"); stream << Xstream; ui->lineEdit_3->setText("File " + Afilename + " created at folder C:\\TEMP_I18N"); } }
}
@Thanks,
Daniel -
File name encoding is dictated by the file system. In case of Windows and NTFS, all file names are UTF-16. As far as I am aware, you cannot change this.
See this for more info: "link":http://en.wikipedia.org/wiki/Filename#Comparison_of_filename_limitations.
-
I have done it different way:
- On Solaris with locale GB18030 I created file: "阿斯的发送gb18030.txt
- Then copied this file to Windows
- The name is displayed as: Íß˹ÀûµÄ¾¯·½gb18030.txt
- Put this name into QT:
@QString encodedStringGB18030 = "Íß˹ÀûµÄ¾¯·½gb18030.txt";@
- Generate the file in QT application
- Copy this file to Solaris with GB18030
And the name is displayed correclty.
Is it possible to generate file name via QT?
If I done it as workaround maybe it is possible to do this via code?Thanks,
Daniel