Simple QImage animations in Qt

  animation, c++, qimage, qt

I would like to achieve the following in a simple (not necessarily most efficient and/or elegant way): I want to create a 320×200 QImage that I keep updating with setPixel commands. The QImage should be shown on screen and updated whenever something has changed. The could could for example look like this:

QImage image (320, 200, QImage::Format_Indexed8);
while (true) {
    image.setPixel (rand() % 320, rand() % 200, rand() % 16);
    [show updated image]

Do I need to have an event handler etc. to realize this, or is it possible to just have such a simple endless loop in the main program?

Source: Windows Questions C++