Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-85745

Read Chinese character path garbled

    XMLWordPrintable

Details

    • Bug
    • Resolution: Incomplete
    • Not Evaluated
    • None
    • 5.13.0
    • Core: URL Handling
    • None
    • Windows

    Description

      First, I read a Chinese character path in the table from TableView, and then call Qdeug output and openUrl to open this path respectively. We found that there is no problem with the Chinese output by calling Qdebug, but the Chinese path will be garbled if openUrl is used to open it.

      Code:

      int current_row = ui->tableView_properties->currentIndex().row(); 
      
      QModelIndex file_path = model->index(current_row,7); QModelIndex file_name = model->index(current_row,2); 
      
      QString file_path_data = model->data(file_path).toString().trimmed();
      
      QString file_name_data = model->data(file_name).toString().trimmed();
      
      QString Splicing_file_path_data=file_path_data+"\\"+file_name_data;
      QTextCodec*codec=QTextCodec::codecForName("GBK");
      QTextCodec::setCodecForLocale(codec); 
      qDebug()<<Splicing_file_path_data; QDesktopServices::openUrl(QUrl::fromLocalFile(Splicing_file_path_data));
      

      result:

      "E:\\test_data\\T1T2地块(国奥)(P065)\\中标通知书"//This is the correct Chinese character path,Use the output of Qdebug
      
      ShellExecute 'file:///E:/test_data/T1T2??飨????)(P065)/?б?????' failed (error 5).//This is the error suggested by openurl
      

      I did the test according to your method and found that it is not the problem of access rights, nor the problem of "
      ". Because I can open the file normally when I change the path to English. But there will be this warning in Chinese, and the file cannot be opened.
      For folders with the same path, the results of the two opening methods are quite different.And I also found that "%3F" is used instead for unsupported Chinese fields, and other question marks are no problem.

            QDesktopServices::openUrl(QUrl::fromLocalFile(R"(E:\test_data\成交确认书\)"));
             QDesktopServices::openUrl(QUrl::fromLocalFile("E:/test_data/成交确认书/"));
      
      successful open!
      ShellExecute 'file:///E:/test_data/????????%3F' failed (error 2).
      

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            thiago Thiago Macieira
            zhenyuzaang 张 振宇
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes