Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
2d like what?
tanatos last edited by
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
@class MainWindow : public QMainWindow
explicit MainWindow(QWidget *parent = 0);
void graphic(QCustomPlot *customPlot);
int randInt(int, int);
@MainWindow::MainWindow(QWidget *parent) :
tempr = new QTimer (this);
connect(tempr, SIGNAL(timeout()), this, SLOT(function()));
timeOfFirstData = QTime::currentTime();
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.