title: Can't Store(Save) the QPainter Image
body: <p>I'm combining 2 QImages ("firstImage" and "secondImage") vertically with the help of QPainter. Combined image displays properly, with no error, as seen from the screen shot:</p>
  
  <p><a href="https://ibb.co/X5S4zKm" rel="nofollow noreferrer">Combined Image Displays Properly</a></p>
  
  <p><a href="https://ibb.co/7bQ1mqF" rel="nofollow noreferrer">First Image</a></p>
  
  <p><a href="https://ibb.co/fDqsWV3" rel="nofollow noreferrer">Second Image</a></p>
  
  <p><em>But if I want to store the "combinedImage" by using .save, program halts and I get assert error.</em> </p>
  
  <p>How can I store the combined image into the harddisk?</p>
  
  <p>mainwindow.cpp:</p>
  
  <pre><code>#include "mainwindow.h"
  #include "ui_mainwindow.h"
  #include &lt;QPainter&gt;
  #include &lt;QImage&gt;
  #include &lt;QPaintEvent&gt;
  
  MainWindow::MainWindow(QWidget *parent) :
      QMainWindow(parent),
      ui(new Ui::MainWindow)
  {
      ui-&gt;setupUi(this);
  }
  
  MainWindow::~MainWindow()
  {
      delete ui;
  }
  
  void  MainWindow::paintEvent(QPaintEvent *)
  {
  
      QString firstImagePath = "/home/nvidia/Desktop/TestFolder/firstImage.jpg";
      QString secondImagePath = "/home/nvidia/Desktop/TestFolder/secondImage.jpg";
      QImage firstImage(firstImagePath);
      QImage secondImage(secondImagePath);
      QImage combinedImage;
      QPainter paint(this);
  
      paint.begin(&amp;combinedImage);
      paint.drawImage(0, 0, firstImage);
      paint.drawImage(0, firstImage.height()*1.1, secondImage);
      paint.end();
  
      bool i = firstImage.save("/home/nvidia/Desktop/TestFolder/firstImage-Copy.bmp");
      Q_ASSERT(i);
  
      bool j = combinedImage.save("/home/nvidia/Desktop/TestFolder/combinedImage-Copy.bmp");
      Q_ASSERT(j);
  }   
  </code></pre>
  
  <p>mainwindow.h:</p>
  
  <pre><code>#ifndef MAINWINDOW_H
  #define MAINWINDOW_H
  
  #include &lt;QMainWindow&gt;
  
  namespace Ui {
  class MainWindow;
  }
  
  class MainWindow : public QMainWindow
  {
      Q_OBJECT
  
  public:
      explicit MainWindow(QWidget *parent = 0);
      ~MainWindow();
      void paintEvent(QPaintEvent *);
  
  private:
      Ui::MainWindow *ui;
  };
  
  #endif // MAINWINDOW_H
  </code></pre>
  
  <p>Here is the Qt output:</p>
  
  <pre><code>Starting /home/nvidia/qtprojects/build-CombinedSave-Jetson_TX2-Debug/CombinedSave...
  QPainter::begin: Painter already active
  ASSERT: "j" in file ../CombinedSave/mainwindow.cpp, line 39
  The program has unexpectedly finished.
  /home/nvidia/qtprojects/build-CombinedSave-Jetson_TX2-Debug/CombinedSave crashed
  </code></pre>
  
  <p>firstImage-Copy.bmp is stored  in the TestFolder but combinedImage-Copy.bmp is not..</p>
  
  <p>Some of my system and program properties:</p>
  
  <pre><code>ARMv8 Processor rev 3 (v8l) × 4 ARMv8 Processor rev 0 (v8l) × 2
  Ubuntu 16.04 LTS
  Qt Creator 3.5.1 Based on Qt 5.5.1 (GCC 5.2.1 20151129, 64 bit)
  </code></pre>