I have fixed this problem now, by not unlocking the foreground lock during shutdown. The problem was that variables like QThread::currentThread() might already be invalid when the static foreground locker is destroyed, depending on destruction order.