Fix memory usage of qt-example.py

With the current implementation, the script uses more and more RAM as time goes
on. On my computer, after 7s, the script needs around 1.4GB of RAM and more
than 2GB after 10 but stays at 88.7MB with this patch.