Найти - Пользователи
Полная версия: pyqt6 QFileDialog.getOpenFileName не понимает кирилицу
Начало » Python для экспертов » pyqt6 QFileDialog.getOpenFileName не понимает кирилицу
1
Areostar
QFileDialog.getOpenFileName отказывается обрабатывать выбор файла если название написано не латинскими буквами

UnicodeEncodeError: ‘charmap’ codec can't encode characters in position 38-46: character maps to <undefined>

Как выправить эту проблему?
Areostar
так. удалось выяснить что сам диалог отрабатывает но в path содержиться какието не юникодовские символы.

как лечить этот глюк?
Areostar
Вот мой код

   def select_files(self, ch) -> None:
        if self.config.get_files_type() == 0:
            path = QFileDialog.getOpenFileName(self, "Open a file", "",
                                           "All Files (*.pdf *.png *.jpeg *.jpg *.docx, xlsx)")
            if path != ('', ''):
                self.content.add_file_to_list(path[0])
                self.fileList.addItem(path[0].split('/')[-1])
        if self.config.get_files_type() == 1:
            folder_path = QFileDialog.getExistingDirectory(self, "Choose Directory")
            if folder_path != ('', ''):
                for root, dirs, files in os.walk(folder_path):
                    for file in files:
                        if Path(file).suffix in ['.pdf', '.png', '.jpeg', '.jpg', '.docx', 'xlsx']:
                            self.content.add_file_to_list(folder_path+'/'+file)
                            self.fileList.addItem(str(file))
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB