Arend
9th March 2013, 10:47
Hello,
When I implement the code below I get the error: 'class MainWindow' has no member named 'customPlot'
What can I do to solve this?
Regards,
Arend (absolute beginner)
mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QtCore>
#include <QtGui>
#include "qcustomplot.h"
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private slots:
void on_pushButtonSwap_clicked();
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
mainwindow.cpp:
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "QtCore"
#include "QtGui"
#include "QDebug"
#include "QMessageBox"
#include <QVector>
#include <cmath>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_pushButtonSwap_clicked()
{
// generate some data:
QVector<double> x(101), y(101);
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
}
this->customPlot->addGraph();
this->customPlot->graph(0)->setData(x, y);
this->customPlot->xAxis->setLabel("x");
this->customPlot->yAxis->setLabel("y");
this->customPlot->xAxis->setRange(-1, 1);
this->customPlot->yAxis->setRange(0, 1);
this->customPlot->replot();
}
When I implement the code below I get the error: 'class MainWindow' has no member named 'customPlot'
What can I do to solve this?
Regards,
Arend (absolute beginner)
mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QtCore>
#include <QtGui>
#include "qcustomplot.h"
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private slots:
void on_pushButtonSwap_clicked();
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
mainwindow.cpp:
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "QtCore"
#include "QtGui"
#include "QDebug"
#include "QMessageBox"
#include <QVector>
#include <cmath>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_pushButtonSwap_clicked()
{
// generate some data:
QVector<double> x(101), y(101);
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
}
this->customPlot->addGraph();
this->customPlot->graph(0)->setData(x, y);
this->customPlot->xAxis->setLabel("x");
this->customPlot->yAxis->setLabel("y");
this->customPlot->xAxis->setRange(-1, 1);
this->customPlot->yAxis->setRange(0, 1);
this->customPlot->replot();
}