diff --git a/src/corelib/kernel/qabstracteventdispatcher.cpp b/src/corelib/kernel/qabstracteventdispatcher.cpp index 685a0c595a..b2bc199c8c 100644 --- a/src/corelib/kernel/qabstracteventdispatcher.cpp +++ b/src/corelib/kernel/qabstracteventdispatcher.cpp @@ -90,7 +90,14 @@ Q_GLOBAL_STATIC(QtTimerIdFreeList, timerIdFreeList) int QAbstractEventDispatcherPrivate::allocateTimerId() { - return timerIdFreeList()->next(); + // This function may be called after timerIdFreeList() has been destructed + // for example in case when application exits without waiting for + // running threads to exit and running thread finished() has been connected + // to a slot which triggers a sequence that registers new timer. + // See https://bugreports.qt-project.org/browse/QTBUG-38957. + if (QtTimerIdFreeList *fl = timerIdFreeList()) + return fl->next(); + return 0; // Note! returning 0 generates a warning } void QAbstractEventDispatcherPrivate::releaseTimerId(int timerId)