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&#40;filename&#41;;
        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


  • Moderators

    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:

    1. On Solaris with locale GB18030 I created file: "阿斯的发送gb18030.txt
    2. Then copied this file to Windows
    3. The name is displayed as: Íß˹ÀûµÄ¾¯·½gb18030.txt
    4. Put this name into QT:

    @QString encodedStringGB18030 = "Íß˹ÀûµÄ¾¯·½gb18030.txt";@

    1. Generate the file in QT application
    2. 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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.