title: QPainter not active
body: <p>The following code results in a bunch of errors:</p>
  
  <pre><code>void MainWindow::displayBoard()
  {
      QPixmap pix(0,0);
      pix.fill(Qt::white);
      QPainter painter(&amp;pix);
      painter.setBrush(Qt::black);
      for(int row = 0; row &lt; 8; row++)
          for(int col = 0; col &lt; 8; col++)
              painter.drawRect(row * 10, col * 10, 10, 10);
      ui-&gt;label-&gt;setPixmap(pix);
  }
  </code></pre>
  
  <p>The errors:</p>
  
  <pre class="lang-none prettyprint-override"><code>QPainter::begin: Paint device returned engine == 0, type: 2
  QPainter::setBrush: Painter not active
  QPainter::drawRects: Painter not active
  </code></pre>
  
  <p>How can I resolve this error?</p>