2d like what?
-
hey
i need to do a program that plots a real time graphic on a X-Y axis. the x axis needs to run constantly while the program is opened for every second. and the y axis needs to aquire a random integer with low and high limits (for example, 20 to 95) and plot that integer for every second, or milisecond linked to x axis.
i know that is possible with “q custom plot” and it needs to be done with it but i dunno how to implement that. can i use the qtimer class to generate the aleatory number while the program is running in real time?here is my code
HEADER
@class MainWindow : public QMainWindow
{
Q_OBJECTpublic:
explicit MainWindow(QWidget *parent = 0);
void graphic(QCustomPlot *customPlot);
int randInt(int, int);
~MainWindow();private:
Ui::MainWindow *ui;
QTimer *tempr;
};@MAINWINDOW.CPP
@MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
graphic(ui->customPlot);
tempr = new QTimer (this);
connect(tempr, SIGNAL(timeout()), this, SLOT(function()));
timeOfFirstData = QTime::currentTime();
tempr->start(1000);
}MainWindow::~MainWindow()
{
delete ui;
killTimer(tempr);
}int MainWindow::function(int lw, int hh)
{
return qrand() % ((hh + 1) - lw) + lw;
}void MainWindow::graphic(QCustomPlot *customPlot)
{
QVector<double> x, y;QTime currentTime = QTime::currentTime(); double timeSinceStart = timeOfFirstData.msecsTo(currentTime)/1000.0; customPlot->addGraph(); customPlot->graph(0)->)->setData(numberOfDataPoint/(double)samplingRate,dataPoint); customPlot->xAxis->setLabel("Time"); customPlot->yAxis->setLabel("Aleatory Integer"); customPlot->xAxis->setRange(timeSinceStart-(numSampleToDisplay/samplingRate),timeSinceStart); customPlot->yAxis->setRange(20, 95); customPlot->replot();
}@
how can i call the "function" while the program is running?
would someone give me a hand on how to implement this code?thanks a lot!
-
Hi and welcome to devnet,
@connect(tempr, SIGNAL(timeout()), this, SLOT(function()));@
This line is wrong, function() doesn't exist in your class. I would recommend that you first have a look at the "Signals & Slots" chapter of Qt's documentation.