Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to create non-Unicode file name in Windows like GB18030 encoding
Forum Updated to NodeBB v4.3 + New Features

How to create non-Unicode file name in Windows like GB18030 encoding

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 1.6k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    nagardd
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      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.

      (Z(:^

      1 Reply Last reply
      0
      • N Offline
        N Offline
        nagardd
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved