title: Histogram with QWT in Microsoft Visual Studio and Qt addin which closes immediately
body: <p>I am using Qt add in for Visual Studio C++ for my GUI.</p>
  
  <p>And on my GUI, I have a button called the plotButton which will draw an histogram of the image when clicked. My plotting option is via the usage of QWT.</p>
  
  <p>However, it does not seem to be plotting anything and closes almost immediately. Tried sleep(), but it doesn't seem to work either. Could the problem be with my code?
  Here is my code for reference:</p>
  
  <pre><code>void qt5test1 ::on_plotButton_clicked()
  {
      //Convert to grayscale
      cv::cvtColor(image, image, CV_BGR2GRAY);
  
  
      int histSize[1] = {256}; // number of bins
      float hranges[2] = {0.0, 255.0}; // min andax pixel value
      const float* ranges[1] = {hranges};
      int channels[1] = {0}; // only 1 channel used
  
      cv::MatND hist;
      // Compute histogram
      calcHist(&amp;image, 1, channels, cv::Mat(), hist, 1, histSize, ranges);
  
      double minVal, maxVal;
      cv::minMaxLoc(hist, &amp;minVal, &amp;maxVal);//Locate max and min values
  
      QwtPlot plot; //Create plot widget
      plot.setTitle( "Plot Demo" ); //Name the plot
      plot.setCanvasBackground( Qt::black ); //Set the Background colour
      plot.setAxisScale( QwtPlot::yLeft, minVal, maxVal ); //Scale the y-axis
      plot.setAxisScale(QwtPlot::xBottom,0,255); //Scale the x-axis
      plot.insertLegend(new QwtLegend()); //Insert a legend
  
      QwtPlotCurve *curve = new QwtPlotCurve(); // Create a curve
      curve-&gt;setTitle("Count"); //Name the curve
      curve-&gt;setPen( Qt::white, 2);//Set colour and thickness for drawing the curve 
      //Use Antialiasing to improve plot render quality
      curve-&gt;setRenderHint( QwtPlotItem::RenderAntialiased, true );
      /*Insert the points that should be plotted on the graph in a 
      Vector of QPoints or a QPolgonF */
      QPolygonF points;
      for( int h = 0; h &lt; histSize[0]; ++h) {
          float bin_value = hist.at&lt;float&gt;(h);
          points &lt;&lt; QPointF((float)h, bin_value);
      }
  
      curve-&gt;setSamples( points ); //pass points to be drawn on the curve
      curve-&gt;attach( &amp;plot ); // Attach curve to the plot 
      plot.resize( 600, 400 ); //Resize the plot
      plot.replot();
      plot.show(); //Show plot
      Sleep(100);
  }
  </code></pre>
  
  <p>Upon clicking this button after loading the image, a window appear and disappear immediately. Under the output window, the lines can be found.</p>
  
  <pre><code>First-chance exception at 0x75d54b32 (KernelBase.dll) in qt5test1.exe: Microsoft C++ exception: cv::Exception at memory location 0x0044939c..
  Unhandled exception at 0x75d54b32 (KernelBase.dll) in qt5test1.exe: Microsoft C++ exception: cv::Exception at memory location 0x0044939c..
  </code></pre>
  
  <p>Does anybody have any idea what could be wrong with my code? Thanks. Please note once again that the program is build, and written within Microsoft Visual Studio C++. Thanks.</p>