Pregunta

I'm trying to use QCustomPlot example (below) in VS2012 , 64 bit Win7 with Qt plugin http://www.qcustomplot.com/index.php/tutorials/basicplotting

#include "customf.h"
#include "../../qcustomplot.h"

customf::customf(QWidget *parent)
    : QMainWindow(parent)
{
    ui.setupUi(this);

QCustomPlot * customPlot; 

// code from example
// generate some data:
QVector<double> x(101), y(101); // initialize with entries 0..100
for (int i=0; i<101; ++i)
{
  x[i] = i/50.0 - 1; // x goes from -1 to 1
  y[i] = x[i]*x[i]; // let's plot a quadratic function
}
// create graph and assign data to it:
customPlot->addGraph();
customPlot->graph(0)->setData(x, y);
// give the axes some labels:
customPlot->xAxis->setLabel("x");
customPlot->yAxis->setLabel("y");
// set axes ranges, so we see all data:
customPlot->xAxis->setRange(-1, 1);
customPlot->yAxis->setRange(0, 1);
customPlot->replot();`enter code here`

}

QcustomPlot code files were added to location: D:\userdata\userXYZ\My Documents\Visual Studio 2012\Projects, that's why I #include "../../qcustomplot.h"
Code was compiled with warning C4700: uninitialized local variable 'customPlot' used.

When I run application it stop working after 1 second.

Could someone please help with finding what is not correctly set, oh how code should look like? Maybe I missed some setting in VS?

Thanks!

¿Fue útil?

Solución

Allocate customPlot before using it.

QCustomPlot * customPlot = new QCustomPlot;

And do not forget to delete it. Or let Qt handle this for you :

 QCustomPlot * customPlot = new QCustomPlot(this);
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top