Uploaded image for project: 'Qt for Python'
  1. Qt for Python
  2. PYSIDE-2359

Windows file dialog causes errors after using QFileIconProvider when faulthandler is enabled

    XMLWordPrintable

Details

    • Bug
    • Resolution: Out of scope
    • Not Evaluated
    • None
    • 5.15.9, 6.5.0
    • PySide
    • None
    • Windows

    Description

      I encountered a strange problem when calling a native file dialog after extracting the icon of a file. The problem only occurs in MS Windows 10 but not in Linux. It appears with Qt5 as well as Qt6 and also with PyQt and PySide binders.

      The error message contains "Windows fatal exception: code 0x8001010e".
      These fatal exceptions seem to appear in another thread because the execution of the python script is not aborted. Calling the native file dialog with tkinter causes the same problems, and using non-native file dialogs does not cause errors.

      After searching, the most similar case I encountered was this.

      To reproduce the errors and workarounds, I created a narrowed-down example script that can be executed normally with

      python filedialog_problem.py

      .

      contents of

      filedialog_problem.py

      with further details:

      """executed in MS Windows 10 with python 3.11.3"""
      
      import faulthandler
      faulthandler.enable()
      
      """the problem occurs with all Qt bindings and Qt versions"""
      # from PySide2 import QtCore, QtGui, QtWidgets
      # from PyQt5 import QtCore, QtGui, QtWidgets # e.g. Qt 5.15.9
      from PySide6 import QtCore, QtGui, QtWidgets # e.g. Qt 6.5.0
      # from PyQt6 import QtCore, QtGui, QtWidgets
      
      
      def filedialog1(native=True):
          options = QtWidgets.QFileDialog.Option(0)
          if not native:
              options = QtWidgets.QFileDialog.Option.DontUseNativeDialog
          filename = QtWidgets.QFileDialog.getSaveFileName(
              None, 'asdf', r'C:\temp', "*.*", options=options
          )
      
      
      def filedialog2():
          from tkinter import filedialog
          filepath = filedialog.askopenfilename()
      
      
      app = QtWidgets.QApplication([])
      
      """if one of the next two lines is uncommented, there are no errors"""
      # filedialog1()
      # filedialog2()
      
      """opening a non-native dialog before does not prevent the errors"""
      # filedialog1(False)
      
      
      iconprovider = QtWidgets.QFileIconProvider()
      icon = iconprovider.icon(QtCore.QFileInfo())
      
      """when using the following two icons instead of the previously defined one,
      then there are also no errors"""
      # icon = QtGui.QIcon(r'C:\temp\some_existing_image.png')
      # icon = iconprovider.icon(iconprovider.IconType.Trashcan)
      
      pm = icon.pixmap(256, 256)
      pm.save(r'C:\temp\extracted_icon.png') # this also works
      
      """when calling the native dialog, the errors occur"""
      filedialog1()
      # filedialog2()
      
      """but when calling the non-native dialog, there are no errors"""
      # filedialog1(False)
      
      
      r"""
      example output:
      
      C:\Users\user\Desktop>python filedialog_problem.py
      Windows fatal exception: code 0x8001010e
      
      Thread 0x00000e18 (most recent call first):
        File "C:\Users\user\Desktop\filedialog_problem.py", line 17 in filedialog1
        File "C:\Users\user\Desktop\filedialog_problem.py", line 47 in <module>
      Windows fatal exception: code 0x8001010e
      
      Thread 0x00000e18 (most recent call first):
        File "C:\Users\user\Desktop\filedialog_problem.py", line 17 in filedialog1
        File "C:\Users\user\Desktop\filedialog_problem.py", line 47 in <module>
      Windows fatal exception: code 0x8001010e
      
      ...
      """
      

      The only workarounds I know so far are:

      • using non-native file dialogs
      • ignoring these errors
      • opening a file dialog before extracting the icon

      What I also did, but without success:

      • tried it on a Laptop with Win10 and in a fresh VM with Win10
      • tried it with a new Qt version (6.5.0)
      • disabled anti-virus and tamper protection
      • tried DontUseCustomDirectoryIcons
      • tried with different Python versions
      • tried time.sleep(...) between commands

      The strange thing is that opening the native Windows file dialog and closing it again before getting the icon data makes a difference.

      Attachments

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

        Activity

          People

            crmaurei Cristian Maureira-Fredes
            bdieterm Bernhard Dietermayr
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes