title: Wave diagram in QT (functionality issues in logic)
body: <p>Wave diagram in QT.. There was some functionality issues in logic. I tried a wave diagram logically using QPainter. Wave diagram is drawn perfectly but there was one line has drawn.. Any one help me to solve this problem. </p>
  
  <p>//dialog.cpp</p>
  
  <pre><code>#include "dialog.h"
  #include "ui_dialog.h"
  #include &lt;QtMath&gt;
  #include &lt;QDebug&gt;
  #include &lt;QDialog&gt;
  #include &lt;QTGui&gt;
  #include &lt;QtCore&gt;
  
  
  Dialog::Dialog(QWidget *parent) :
      QDialog(parent),
      ui(new Ui::Dialog)
  {
      ui-&gt;setupUi(this);
  }
  
  Dialog::~Dialog()
  {
      delete ui;
  }
  
  void Dialog::paintEvent(QPaintEvent *e)
  {
      e-&gt;accept();
  
      float scale = 40;
      //boolean negativeX = true;
      float width = 500;
      float height = 108;
  
      QPainter painter(this);
  
      QPen linepen(Qt::red);
      linepen.setWidth(2);
      QPoint p1;
      QPoint p2;
  
      painter.setPen(linepen);
  
      float xx, yy, dx=4, x0=width / 2, y0=height / 2;
  
      //float iMax = (width - x0) / dx;
      float iMax = 63;
  
      //float iMin = negativeX ? -x0 / dx : 0;
      float iMin = -63;
  
      for (int i=iMin;i&lt;=iMax;i++) {
             float x = x0+xx;
             float y = y0-yy;
           p1.setX(x);
           p1.setY(y);
  
           xx = dx*i;
           float xscl = xx/scale;
           yy = scale * qCos( 3* xscl );
  
             x = x0+xx;
             y = y0-yy;
  
           p2.setX(x);
           p2.setY(y);
  
           painter.drawLine(p1, p2);
  
       }
  
     }
  </code></pre>
  
  <p>// dialog.h</p>
  
  <pre><code>protected:
      void paintEvent(QPaintEvent *e);
  </code></pre>
  
  <p>// main.cpp</p>
  
  <pre><code>QApplication a(argc, argv);
  Dialog w;
  w.show();
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/DEI9R.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/DEI9R.png" alt="enter image description here"></a></p>