QCustomPlot was used as an aid for drawing graphics in Qt Creator (installed correctly as the example was compiled)

inline double fn(int T, double x) { if (x >= 0) return T; return 0; } void MainWindow::drawfunc(int valT, int xmin, int xmax) //Π’Ρ‹Π²ΠΎΠ΄ Ρ„ΡƒΠ½ΠΊΡ†ΠΈΠΈ Π₯эвисайда { double hh =0.01; int N = (xmax-xmin)/hh;//считаСтся количСство Ρ‚ΠΎΡ‡Π΅ΠΊ для массивов ΠΊΠΎΠΎΡ€Π΄ΠΈΠ½Π°Ρ‚ xmax=10,xmin=-5 ΠΈΡ‚ΠΎΠ³ΠΎ 1500 QVector<double> x11(N), y11(N); // //ΠœΠ°ΡΡΠΈΠ²Ρ‹ ΠΊΠΎΠΎΡ€Π΄ΠΈΠ½Π°Ρ‚ Ρ‚ΠΎΡ‡Π΅ΠΊ int i=0; for (double x = xmin; x < xmax; x +=hh) { x11[i]=x; y11[i]=fn(valT,x); i++; } ui->widget->clearGraphs(); ui->widget->addGraph(); ui->widget->graph(0)->setData(x11, y11); // Π·Π°Π΄Π°Π΅ΠΌ ΠΈΠΌΠ΅Π½Π° осСй ΠΊΠΎΠΎΡ€Π΄ΠΈΠ½Π°Ρ‚ ui->widget->xAxis->setLabel("x"); ui->widget->yAxis->setLabel("y"); // Π·Π°Π΄Π°Π΅ΠΌ Ρ€Π°Π·ΠΌΠ΅Ρ€Ρ‹ осСй ui->widget->xAxis->setRange(xmin, xmax); ui->widget->replot(); } 

The problem is that the graph is not drawn, an exception crashes.

enter image description here

 ASSERT failure in QVector<T>::operator[]: "index out of range", file ..\..\..\..\Qt\5.3\mingw482_32\include/QtCore/qvector.h, line 385 

Step by step during debugging it turned out that:

- problem due to QVector

enter image description here

The number of points is 1500 (manual formula calculation), Qt Creator produces 1499.

Such simple techniques as

 int N = ((xmax-xmin)/hh)+1 ΠΈΠ»ΠΈ `QVector<double> x11(N+1), y11(N+1)` `i=1` 

also give an exception ..

    1 answer 1

    It all worked. Since I was transferring the working code from Visual Studio I decided to look at the number of iterations there.

    Showed 1501 . In qt creator i also showed 1501 but the QVector point array itself was 1499 . As a result, the formula for obtaining the number of points was added +2

     int N = ((xmax-xmin)/hh)+2 

    Total

    The number of points coincides with the number of iterations and the program works.