Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. 2d like what?

2d like what?

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 948 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    tanatos
    wrote on last edited by
    #1

    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_OBJECT

    public:
    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!

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved