Remove bogus duplicate check
The second condition can never be fulfilled on the first iteration (QDirIterator does not return a path twice), but only after the QDirIterator has been reset in the outer loop.
As validThumbnails is incremented when hadFirstThumbnail gets assigned, the outer loop will never be run after the initial assignement of hadFirstThumbnail, so the condition can never be true.