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. QFileDialog::getOpenFileName causing program to crash

QFileDialog::getOpenFileName causing program to crash

Scheduled Pinned Locked Moved Unsolved General and Desktop
26 Posts 12 Posters 5.6k Views
  • 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.
  • J JonB
    23 Feb 2023, 06:59

    @crackysk said in QFileDialog::getOpenFileName causing program to crash:

    Since application has been working for years (3 more precisely) before this without any issues, my guess would be that some kind of Windows (also using Win10) update messed something up, but can't be sure about it.

    It is highly likely this is the case, sadly. I don't know what you can do about it (sometimes it's possible the next patch/update corrects an issue), but you might verify:

    • I think it's clear the error comes when using the native Windows Save File dialog. Try passing QFileDialog::DontUseNativeDialog? But I'm not sure that works with getSaveFileName(), you may also have to try...
    • ... Use a QFileDialog instance and setAcceptMode(QFileDialog::AcceptSave) to try your own code instead of the inbuilt static QFileDialog::getSaveFileName().

    At least you will know what is required to reproduce the issue.

    C Offline
    C Offline
    crackysk
    wrote on 23 Feb 2023, 20:52 last edited by
    #15

    @JonB
    I've tried first option before posting yesterday, but forgot to mention it (knew I would forget something).
    Today I tried the approach with using QFileDialog instance and still have same issue.

    One interesting thing is that with QFileDialog::DontUseNativeDialog set to false application works "slightly better". Let me try to elaborate:

    • When set to false, Windows dialog opens fully, shows a content of starting location folder, but then freezes and runs send problem report mechanism
    • When set to true, something I believe should be Qt dialog opens, but dialog is fully white without any useful information and instantly runs send problem report mechanism

    Will try to play further with it and see if I can make it work somehow.
    Thank you for your replies and time.

    1 Reply Last reply
    0
    • L Offline
      L Offline
      LaCucaracha
      wrote on 24 Feb 2023, 16:08 last edited by
      #16

      I've had the same issue in the last few days and managed to get around it.

      I've had the same backtrace as shown above. On an app that worked for years. Qt 5.9 and now 5.15. Windows 10.

      I don't use a QFileDialog but a QFileSystemModel set into a QTreeView.
      When there is nothing to display, there is no crash (TreeView hidden, Model not set or Rootpath and Filters set to display an empty location).

      My solution was to remove the icons from the display by overriding the function data() of QFileSystemModel to ignore the Qt::DecorationRole :

      QVariant MyCustomFileModel::data(const QModelIndex& index, int role) const
      {
          if (role == Qt::DecorationRole)
              return QVariant();
          else
              return QFileSystemModel::data(index, role);
      }
      

      No icons. But it works.

      Digging further, i made my own QFileIconProvider to give to the model.
      The function icon is the issue.

      QIcon QFileIconProvider::icon(const QFileInfo &info) const
      

      If i override it to return QIcon() it works fine, with icons. They might be different from what they were before and there might be some missing ones but i'm not sure. Probably has to do with the style of the application. (No custom style applied here)

      For the next step, looking into QFileIconProviderPrivate, QGuiApplicationPrivate and QPlatformTheme might be a bit too much for my skills.

      Also, the options QFileIconProvider::DontUseCustomDirectoryIcons and all of the QFileSystemModel options (DontWatchForChanges, DontResolveSymlinks, DontUseCustomDirectoryIcons) do not change anything.

      C 1 Reply Last reply 26 Feb 2023, 11:59
      1
      • L LaCucaracha
        24 Feb 2023, 16:08

        I've had the same issue in the last few days and managed to get around it.

        I've had the same backtrace as shown above. On an app that worked for years. Qt 5.9 and now 5.15. Windows 10.

        I don't use a QFileDialog but a QFileSystemModel set into a QTreeView.
        When there is nothing to display, there is no crash (TreeView hidden, Model not set or Rootpath and Filters set to display an empty location).

        My solution was to remove the icons from the display by overriding the function data() of QFileSystemModel to ignore the Qt::DecorationRole :

        QVariant MyCustomFileModel::data(const QModelIndex& index, int role) const
        {
            if (role == Qt::DecorationRole)
                return QVariant();
            else
                return QFileSystemModel::data(index, role);
        }
        

        No icons. But it works.

        Digging further, i made my own QFileIconProvider to give to the model.
        The function icon is the issue.

        QIcon QFileIconProvider::icon(const QFileInfo &info) const
        

        If i override it to return QIcon() it works fine, with icons. They might be different from what they were before and there might be some missing ones but i'm not sure. Probably has to do with the style of the application. (No custom style applied here)

        For the next step, looking into QFileIconProviderPrivate, QGuiApplicationPrivate and QPlatformTheme might be a bit too much for my skills.

        Also, the options QFileIconProvider::DontUseCustomDirectoryIcons and all of the QFileSystemModel options (DontWatchForChanges, DontResolveSymlinks, DontUseCustomDirectoryIcons) do not change anything.

        C Offline
        C Offline
        crackysk
        wrote on 26 Feb 2023, 11:59 last edited by
        #17

        @LaCucaracha

        Thank you for reply. I even tried QFileIconProvider::DontUseCustomDirectoryIcons at some point, but didn't cross my mind that's not doing anything useful.

        I tried providing icon provider directly to static QFileDialog for save/open file that I was using, but it made no difference. Also, creating custom FileIconProvider and providing it to instance of QFileDialog created in app made no difference (also creating custom QFileDialog class).
        So, I basically moved to same thing as you did. I've written my own dialog that's doing same thing as static one I was using before.
        Now, I have treeView and listView next to each other, both of them provided with different QFileSystemModel (different when it comes to filter) and provided custom QFileIconProvider class that has icon() overridden. And really, crashes are gone!

        Honestly, I don't even mind having same file icon for each file type. For purposes I need it for, this is more than enough. But, if someone needs it, probably can even do similar thing like you did for a role and look for a specific QFileInfo that makes a mess and for all others use just default constructor for QIcon as you did.

        All that's left to do is handling cosmetics in order to make this new QDialog as close as possible to the one.

        1 Reply Last reply
        0
        • V Offline
          V Offline
          Vsevolod7
          wrote on 3 Mar 2023, 19:44 last edited by
          #18

          Same problem.

          1 Reply Last reply
          0
          • ? Offline
            ? Offline
            A Former User
            wrote on 4 Mar 2023, 09:30 last edited by
            #19

            I copy your codes and run it on win11 successfully. I used Qt5.13 and the compiler 'MingGW 64bit'. Add I tried the compiler 'MSVC2015', it is all right too. I think our developing environment are similar to each other.

            1 Reply Last reply
            0
            • A Offline
              A Offline
              az1699
              wrote on 14 Mar 2023, 10:52 last edited by az1699
              #20

              Same issue here. I've a test application made few months ago that always worked. I fixed by working around using DontUseNativeDialog.

              If I run the same application, same build, on windows sand box it works perfectlly. Dont know why, windows sand box should have the same windows system update as my system

              1 Reply Last reply
              0
              • A Offline
                A Offline
                az1699
                wrote on 14 Mar 2023, 11:46 last edited by
                #21

                I also tried this, don't why but after istancing QFileDialog with QFileDialog::DontUseNativeDialog I can start using QFileDialog in the previous way. I tested this simple example and works.

                    static bool first_run = true;
                    if (first_run) {
                        CmdOpenFile(QFileDialog::getOpenFileName(0, "Open some file", QString(), QObject::tr("All files (*.*)"), nullptr, QFileDialog::DontUseNativeDialog));
                        first_run = false;
                    } else {
                        CmdOpenFile(QFileDialog::getOpenFileName(0, "Open some file", QString(), QObject::tr("All files (*.*)")));
                    }
                
                1 Reply Last reply
                0
                • V Offline
                  V Offline
                  Violet Giraffe
                  wrote on 14 Mar 2023, 12:55 last edited by Violet Giraffe
                  #22

                  I can't speak for every case in particular, but these symptoms are very typical for a misbehaving shell / Explorer extension, and not related to Qt, most likely.

                  I've seen some projects (for example - Firefox) maintain a list of known faulty DLLs and use LoadLibrary hooks to prevent those DLLs from loading.

                  1 Reply Last reply
                  2
                  • S Offline
                    S Offline
                    sir_clive
                    wrote on 15 Mar 2023, 13:21 last edited by sir_clive
                    #23

                    I'd like to add my experience with this issue.

                    I pulled my hair out over a very similar (probably the same?) problem lately, and it turned out that AVAST and AVG (practically the same product) are causing this problem in my case. These programs must be uninstalled (not deactivated, but completely uninstalled) for my program to start working again.

                    My program was working on multiple versions of Windows for years already, with no issues whatsoever. The problems started in February this year (2023), and affect every single "file dialog" instance my program tries to open.

                    The tip with not using native dialog did not help in my case. Also VMWare based Windows installations are not affected, only the "bare metal" ones. Also, 5.x and 6.x QT versions are both crashing if AVAST or AVG are installed.

                    I'm surprised not more QT programs are affected, this is the best thread I found so far.

                    A 1 Reply Last reply 15 Mar 2023, 14:32
                    0
                    • S sir_clive
                      15 Mar 2023, 13:21

                      I'd like to add my experience with this issue.

                      I pulled my hair out over a very similar (probably the same?) problem lately, and it turned out that AVAST and AVG (practically the same product) are causing this problem in my case. These programs must be uninstalled (not deactivated, but completely uninstalled) for my program to start working again.

                      My program was working on multiple versions of Windows for years already, with no issues whatsoever. The problems started in February this year (2023), and affect every single "file dialog" instance my program tries to open.

                      The tip with not using native dialog did not help in my case. Also VMWare based Windows installations are not affected, only the "bare metal" ones. Also, 5.x and 6.x QT versions are both crashing if AVAST or AVG are installed.

                      I'm surprised not more QT programs are affected, this is the best thread I found so far.

                      A Offline
                      A Offline
                      az1699
                      wrote on 15 Mar 2023, 14:32 last edited by
                      #24

                      @sir_clive I've Avast antivurs on my computer, i tested in an other without avast and works :(

                      So maybe reporting this issue the could fix it

                      1 Reply Last reply
                      0
                      • B bdieterm referenced this topic on 29 May 2023, 16:47
                      • V Offline
                        V Offline
                        VirtualFloat
                        wrote on 6 Mar 2025, 07:16 last edited by
                        #25

                        Running into the same issue here on some corporate windows 11 machines. So in 2025 it is still causing issues.

                        V 1 Reply Last reply 6 Mar 2025, 18:48
                        0
                        • V VirtualFloat
                          6 Mar 2025, 07:16

                          Running into the same issue here on some corporate windows 11 machines. So in 2025 it is still causing issues.

                          V Offline
                          V Offline
                          Violet Giraffe
                          wrote on 6 Mar 2025, 18:48 last edited by
                          #26

                          @VirtualFloat
                          Does the crash occur in a Qt .dll, or inside a foreign dll injected by some security software? The latter is, unfortunately, not uncommon.

                          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