QFileDialog::getOpenFileName causing program to crash
-
@BogdanPopa said in QFileDialog::getOpenFileName causing program to crash:
2 on_avast_dll_unload 0x7ffac8365310
Try disabling your Avast virus protector and see if it goes away?
-
@BogdanPopa
Then I would expect you to be able to post a stack trace which does not show it dying inon_avast_dll_unload
? -
I'm having similar issue as @BogdanPopa mentioned above.
Using QFileDialog::getSaveFileName instead of Open, but same concept...
Also, initial backtrace looked similar and contained avast detail, but managed to get past it and get a complete backtrace that has more sense...1 ntdll!RtlCompareMemoryUlong 0x7ff8dab71aa0 2 ntdll!RtlAllocateHeap 0x7ff8daafdd00 3 ntdll!RtlAllocateHeap 0x7ff8daafb44d 4 ntdll!RtlRegisterSecureMemoryCacheCallback 0x7ff8dabc8c38 5 ntdll!RtlAllocateHeap 0x7ff8daafd255 6 ntdll!RtlAllocateHeap 0x7ff8daafb44d 7 Windows.Storage!CFreeThreadedItemContainer_CreateInstance 0x7ff8d635ba26 8 Windows.Storage!CFreeThreadedItemContainer_CreateInstance 0x7ff8d635b4be 9 Windows.Storage!CCachedShellItem_CreateInstance 0x7ff8d635a3d2 10 Windows.Storage!ILFindLastID 0x7ff8d636fc65 11 Windows.Storage!SHCreateShellItemArrayFromIDLists 0x7ff8d640323f 12 Windows.Storage!SHChangeNotification_Lock 0x7ff8d6414537 13 EXPLORERFRAME!DllGetClassObject 0x7ff8a4a08a46 14 EXPLORERFRAME!DllCanUnloadNow 0x7ff8a4a7d52a 15 ?? 0x7ff8a4a01603 16 ?? 0x7ff8a49ffa15 17 EXPLORERFRAME!DllGetClassObject 0x7ff8a4a3d680 18 ?? 0x7ff8a49f873d 19 ?? 0x7ff8a49f8551 20 DefSubclassProc 0x7ff8bc959aba 21 DSA_Create 0x7ff8bc9598b7 22 USER32!CallWindowProcW 0x7ff8d979e7e8 23 USER32!DispatchMessageW 0x7ff8d979e229 24 USER32!IsDialogMessageW 0x7ff8d979bfe0 25 USER32!DialogBoxIndirectParamAorW 0x7ff8d97bd8f6 26 USER32!DialogBoxIndirectParamAorW 0x7ff8d97bd5a1 27 USER32!DialogBoxIndirectParamAorW 0x7ff8d97bd452 28 USER32!DialogBoxIndirectParamW 0x7ff8d97bd3e8 29 DllCanUnloadNow 0x7ff8d8c4617e 30 GetFileTitleW 0x7ff8d8c23064 31 QWindowsNativeFileDialogBase::doExec qwindowsdialoghelpers.cpp 962 0x1e8480d9 32 QWindowsNativeDialogBase::exec qwindowsdialoghelpers.cpp 183 0x1e937a97 33 QWindowsDialogHelperBase<QPlatformFileDialogHelper>::exec qwindowsdialoghelpers.cpp 394 0x1e937a97 34 QDialog::exec qdialog.cpp 553 0x67e6c699 35 QFileDialog::getSaveFileUrl qfiledialog.cpp 2434 0x67e7efa6 36 QFileDialog::getSaveFileName qfiledialog.cpp 2381 0x67e7f16b 37 MainWindow::getDestination mainwindow.cpp 288 0x4048ef 38 MainWindow::qt_static_metacall moc_mainwindow.cpp 100 0x407be7 39 QMetaObject::activate qobject.cpp 3778 0x1480c86 40 QMetaObject::activate qobject.cpp 3631 0x1480fa4 41 QAbstractButton::clicked moc_qabstractbutton.cpp 312 0x67d70117 42 QAbstractButtonPrivate::emitClicked qabstractbutton.cpp 414 0x67d70332 43 QAbstractButtonPrivate::click qabstractbutton.cpp 407 0x67d718d0 44 QAbstractButton::mouseReleaseEvent qabstractbutton.cpp 1011 0x67d71b71 45 QWidget::event qwidget.cpp 8888 0x67cc9f42 46 QAbstractButton::event qabstractbutton.cpp 968 0x67d72d2c 47 QPushButton::event qpushbutton.cpp 684 0x67e013ec 48 QApplicationPrivate::notify_helper qapplication.cpp 3752 0x67c8818e 49 QApplication::notify qapplication.cpp 3213 0x67c8f532 50 QCoreApplication::notifyInternal2 qcoreapplication.cpp 1061 0x14570a6 51 QCoreApplication::sendSpontaneousEvent qcoreapplication.cpp 1463 0x14572ec 52 QApplicationPrivate::sendMouseEvent qapplication.cpp 2699 0x67c8e8d6 53 QWidgetWindow::handleMouseEvent qwidgetwindow.cpp 661 0x67cdf5f2 54 QWidgetWindow::event qwidgetwindow.cpp 281 0x67ce1a69 55 QApplicationPrivate::notify_helper qapplication.cpp 3752 0x67c8818e 56 QApplication::notify qapplication.cpp 3109 0x67c8f253 57 QCoreApplication::notifyInternal2 qcoreapplication.cpp 1061 0x14570a6 58 QCoreApplication::sendSpontaneousEvent qcoreapplication.cpp 1463 0x14572ec 59 QGuiApplicationPrivate::processMouseEvent qguiapplication.cpp 2102 0xb31ed65 60 QGuiApplicationPrivate::processWindowSystemEvent qguiapplication.cpp 1837 0xb3201da 61 QWindowSystemInterface::sendWindowSystemEvents qwindowsysteminterface.cpp 1068 0xb303959 62 QWindowsGuiEventDispatcher::sendPostedEvents qwindowsguieventdispatcher.cpp 82 0x1e886ff9 63 qt_internal_proc qeventdispatcher_win.cpp 245 0x14abb5f 64 USER32!CallWindowProcW 0x7ff8d979e7e8 65 USER32!DispatchMessageW 0x7ff8d979e229 66 QEventDispatcherWin32::processEvents qeventdispatcher_win.cpp 639 0x14ab2b9 67 QWindowsGuiEventDispatcher::processEvents qwindowsguieventdispatcher.cpp 74 0x1e886fd7 68 QEventLoop::processEvents qeventloop.cpp 138 0x14557c7 69 QEventLoop::exec qeventloop.cpp 225 0x1455be5 70 QCoreApplication::exec qcoreapplication.cpp 1364 0x145e86e 71 QGuiApplication::exec qguiapplication.cpp 1779 0xb315d9d 72 QApplication::exec qapplication.cpp 2909 0x67c88070 73 qMain main.cpp 10 0x4015c3 74 WinMain qtmain_win.cpp 104 0x409cd2 75 __tmainCRTStartup 0x4013c7 76 WinMainCRTStartup 0x4014cb
Sorry if formatting of backtrace is not ideal...
Also, maybe relevant note, this issue happened on multiple machines (a friend of mine is using application that I provided via installer and reported me an issue and it fails in same manner on both of our machines).
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.I'm currently trying to use newer version of Qt (one I was using is fairly old, 5.12.0) hoping that one with more recent date would include some kind of fix for this, but according to this problem report I don't feel so confident about it. :)
Posting this in case it helps someone else.
-
@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 withgetSaveFileName()
, you may also have to try... - ... Use a
QFileDialog
instance andsetAcceptMode(QFileDialog::AcceptSave)
to try your own code instead of the inbuiltstatic QFileDialog::getSaveFileName()
.
At least you will know what is required to reproduce the issue.
- I think it's clear the error comes when using the native Windows Save File dialog. Try passing
-
@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 usingQFileDialog
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. -
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.
-
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.
-
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.
-
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
-
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 (*.*)"))); }
-
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.
-
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.
-