replace Q_FOREACH with for-range loop, should fix freeBSD compilation

Authored by jjazeix on Feb 4 2020, 7:39 PM.