Please nominate your Qt Champions for 2021!

QFileSystemModel Causing main thread to hang with Qt5.12

  • My application worked normally under Qt 5.11 and MSVC2015. I moved to Qt5.12 and MSVC2017 and now my main thread hangs for 5 - 10s at start up. After this time delay it functions normally. Excluding the QFileSystemModel part of the code and there is no issue.

    I can replicate the effect with a minimalist application.


    #ifndef DIALOG_H
    #define DIALOG_H
    #include <QDialog>
    #include <QFileSystemModel>
    namespace Ui {
    class Dialog;
    class Dialog : public QDialog
        explicit Dialog(QWidget *parent = nullptr);
        Ui::Dialog *ui;
        QFileSystemModel *dirModel;
    #endif // DIALOG_H


    #include "dialog.h"
    #include "ui_dialog.h"
    Dialog::Dialog(QWidget *parent) :
        ui(new Ui::Dialog)
        QString mPath = "C:/";
        dirModel = new QFileSystemModel(this);
        delete ui;

    I do not know how to investigate the main thread hang further. Any suggestions would be helpful.


    [Added code tags ~kshegunov]

  • Moderators

    Interrupt the debugger whenever that delay happens and extract a stack trace for the running threads (I recommend having a debug Qt build for this). From there you can try to trace back where the issue is. QFileSystemModel is supposed to query the filesystem in its own thread, so what you describe is rather odd.

  • @kshegunov

    My knowledge is limited as far as debugging this further.

    If I interrupt the app during debugging I can see this but it does not mean much to me.



  • Moderators

    GetVolumeInformationW shouldn't be there and I can't fathom how it got called ... Can you extract the whole stack trace as text (there should be a context menu entry, i.e. right click, in the shown view pane)? I can't see what's the root of the stack from the image.

    That method is to get the device(s) information. It's called here, and as far as I can tell only there ... so this doesn't add up.

  • @kshegunov

    Sorry for the delay, I am on USA time.

    1 ZwOpenFile ntdll_77aa0000 0x77b0a56c
    2 GetVolumeInformationW KERNELBASE 0x7455d5b5
    3 QTreeViewPrivate::layout Qt5Widgetsd 0x6474aaae
    4 QTreeViewPrivate::layout Qt5Widgetsd 0x6474b7ab
    5 QTreeViewPrivate::layout Qt5Widgetsd 0x6474661c
    6 QTextCodec::codecForHtml Qt5Cored 0x6718737d
    7 QTextCodec::codecForHtml Qt5Cored 0x671818f6
    8 QTreeViewPrivate::layout Qt5Widgetsd 0x647492a0
    9 QTreeViewPrivate::layout Qt5Widgetsd 0x6447879b
    10 QTreeViewPrivate::layout Qt5Widgetsd 0x644747c5
    11 QTextCodec::codecForHtml Qt5Cored 0x671384fc
    12 QTextCodec::codecForHtml Qt5Cored 0x67136879
    13 QTextCodec::codecForHtml Qt5Cored 0x671398f9
    14 QTextCodec::codecForHtml Qt5Cored 0x671d8354
    15 qt_plugin_instance qwindowsd 0xf10c5e0
    16 QTextCodec::codecForHtml Qt5Cored 0x671d699b
    17 _InternalCallWinProc USER32 0x7505bf1b
    18 UserCallWinProcCheckWow USER32 0x750583ea
    19 DispatchMessageWorker USER32 0x75057c9e
    20 DispatchMessageW USER32 0x75057a80
    21 QTextCodec::codecForHtml Qt5Cored 0x671d70d9
    22 qt_plugin_instance qwindowsd 0xf10c5b8
    23 QTextCodec::codecForHtml Qt5Cored 0x6713371c
    24 QTextCodec::codecForHtml Qt5Cored 0x67133927
    25 QTextCodec::codecForHtml Qt5Cored 0x67136692
    26 QGuiApplication::keyboardModifiers Qt5Guid 0x14c06a8
    27 QTreeViewPrivate::layout Qt5Widgetsd 0x64474329
    28 main main.cpp 10 0xc2280f
    29 WinMain qtmain_win.cpp 104 0xc25f9d
    30 invoke_main exe_common.inl 107 0xc241ce
    31 __scrt_common_main_seh exe_common.inl 288 0xc24037
    32 __scrt_common_main exe_common.inl 331 0xc23ecd
    33 WinMainCRTStartup exe_winmain.cpp 17 0xc24248
    34 BaseThreadInitThunk KERNEL32 0x77728484
    35 __RtlUserThreadStart ntdll_77aa0000 0x77b0302c
    36 _RtlUserThreadStart ntdll_77aa0000 0x77b02ffa

  • Lifetime Qt Champion

    Probably this usage is more involved in the problem - even if I don't see it in the stack trace either.

    But I think more interesting would be, why it hangs there, of course. Probably asking for a non-existing, ejected or non-reachable network drive?

  • @aha_1980

    I do have a 'Google Drive' showing up and perhaps it is taking time to read that.

    It seems to hang 90% of the time I try it but sometimes it is not hanging.

    Never had an issue with 5.11 and MSVC2015, only now with 5.12 and MSVC2017.

    Has anything changed in this area 5.11 to 5.12? Any reason why it is hanging the main thread as it should be in its own for just this reason?

  • Lifetime Qt Champion

    Hi @BrianN,

    can you try again with "unmounted" Google Drive? Just to be sure we're on the right track.

    Any reason why it is hanging the main thread as it should be in its own for just this reason?

    No idea. But there are two reports: QTBUG-69086 and QTBUG-65977 that seems related to your problem.

    You should probably comment (and vote) at least at the first report to show the interest in the problem.


  • Lifetime Qt Champion

    Just as a note:
    What windows version are you seeing this on ?
    Windows 7 has very long timeout for shares where as much faster
    in windows 10.

  • @aha_1980

    Disabling Google Drive File Stream made a 95% improvement. I still noticed one delay at start up.

    I am using Windows 10.

    I will check those bug reports now as suggested.


  • Moderators

    My suspicion was a network share causing too long to respond. But I still don't understand this stack trace. There's system function calls that are mixed in the wrong places ...

  • @kshegunov

    I am a novice when it comes to stack traces. Is anyone able to duplicate the small program I am using for testing or can anyone guide me with further tests to carry out?


  • Moderators

    I don't have windows, but I could run it on Linux. However I really doubt it'd manifest the problem. As a side question, have you built Qt yourself, or did you install from a prebuilt package? If you got it ready-made it can be that some debug optimizations are in place, but still the stack trace seems very odd.

  • @kshegunov

    Sorry for the delay, moved from USA to UK.

    I took the standard prebuilt Qt package. Not sure what it has for debug in place?


Log in to reply