Setting QT_QPA_PLATFORM with putenv from a local variable causes the environment to later still refer to it when it's out of scope. Use setenv instead, as it copies the values provided.