title: QPainter::begin crashes the program in debug mode
body: <p><strong>1. Problem description</strong></p>
  
  <p>Calling <a href="http://doc.qt.io/qt-5/qpainter.html#begin" rel="nofollow noreferrer">QPainter::begin</a> works fine when the program is run normally, but causes it to crash when executed in <em>Debug</em> mode. Any ideas what is the reason for that?</p>
  
  <hr>
  
  <p><strong>2. Environment</strong></p>
  
  <ul>
  <li>Windows 7 Pro 64 bit</li>
  <li>Qt 5.9.2</li>
  <li>MSVC 2017</li>
  <li>Windows Kits\10\Debuggers\x64\cdb.exe</li>
  </ul>
  
  <hr>
  
  <p><strong>3. Example code</strong></p>
  
  <p><em>MainWindow.h</em></p>
  
  <pre><code>#include &lt;QMainWindow&gt;
  
  class MainWindow : public QMainWindow
  {
      Q_OBJECT
  public:
      explicit MainWindow(QWidget *parent = nullptr);
  };
  </code></pre>
  
  <p><em>MainWindow.cpp</em></p>
  
  <pre><code>#include "MainWindow.h"
  #include "Painter.h"
  #include &lt;QLabel&gt;
  
  MainWindow::MainWindow(QWidget *parent) :
      QMainWindow(parent)
  {
      auto *label = new QLabel(this);
  
      label-&gt;setPixmap(Painter().paint());
  
      setCentralWidget(label);
  }
  </code></pre>
  
  <p><em>Painter.h</em></p>
  
  <pre><code>#include &lt;QObject&gt;
  
  class Painter : public QObject
  {
      Q_OBJECT
  public:
      explicit Painter(QObject *parent = nullptr);
  
      QPixmap paint();
  };
  </code></pre>
  
  <p><em>Painter.cpp</em></p>
  
  <pre><code>#include "Painter.h"
  #include &lt;QPainter&gt;
  
  Painter::Painter(QObject *parent) : QObject(parent)
  {
  
  }
  
  QPixmap Painter::paint()
  {
      QPainter painter;
      QPixmap pixmap(16, 16);
  
      pixmap.fill(Qt::transparent);
  
      painter.begin(&amp;pixmap); // &lt;-- program crashes here on Debug
  
      return pixmap;
  }
  </code></pre>
  
  <hr>
  
  <p><strong>4. Debugger's output</strong></p>
  
  <p><a href="https://i.stack.imgur.com/Klu5n.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Klu5n.png" alt="enter image description here"></a>
  <a href="https://i.stack.imgur.com/wqsCv.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/wqsCv.png" alt="enter image description here"></a></p>