Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QWT Plot does not update



  • Greetings,

    Have QWT 6.1.5, QT 5.15.0 and MSVC2019, trying to do a plot:

    void MainWindow::setupGraph()
    {
    	QColor c(Qt::black);
    	c.setAlpha(140);
    
    	QPalette pal;
    	pal.setColor(QPalette::Window, c);
    
    	ui->qwtPlot->setTitle("Monitor");
    	ui->qwtPlot->setAxisTitle(QwtPlot::xBottom, "Sec");
    	ui->qwtPlot->setAxisScale(QwtPlot::xBottom, 0, 100, 10);
    	ui->qwtPlot->setAxisTitle(QwtPlot::yLeft, "mV");		// Y axis title
    	ui->qwtPlot->setAxisScale(QwtPlot::yLeft, 0, 100, 10);
    	ui->qwtPlot->setAttribute(Qt::WA_TranslucentBackground);	// background colour
    	ui->qwtPlot->setPalette(pal);
    
    
    	QwtPlotGrid *grid = new QwtPlotGrid();
    	grid->setMajorPen(QPen(Qt::darkGray, 0, Qt::DotLine));		// grid is black dotted
    	grid->attach(ui->qwtPlot);
    
    	curve = new QwtPlotCurve;
    	curve->setPen(QPen(Qt::green));					// plot is green
    	curve->setRenderHint(QwtPlotItem::RenderAntialiased, true);	// plot anti aliased
    	curve->attach(ui->qwtPlot);
    }
    
    void MainWindow::updateGraph()
    {
    	int i = 0;
    
    	while (1) {
    		sec[i] = seconds;
    		qDebug() << "Sec:" << sec[i] << "," << "Ch0:" << ch[i];
    		seconds++;
    		i++;
    		if (i == 5)
    			break;
    	}
    
    	curve->setSamples((double *) sec, (double *) ch, 5);
    	curve->attach(ui->qwtPlot);
    	ui->qwtPlot->replot();
    }
    

    From my MainWindow, I do setupGraph();
    and as I get data, I do an updateGraph();

    The qDebug() debug log messages I can see:

    Sec: 0 , Ch0: 21
    Sec: 1 , Ch0: 24
    Sec: 2 , Ch0: 20
    Sec: 3 , Ch0: 23
    Sec: 4 , Ch0: 22
    Sec: 5 , Ch0: 21
    Sec: 6 , Ch0: 21
    ....

    But the Graph does not seem to plot any points ?
    I can see that the Plot has setup correctly with the set values in setupGraph()

    Am I missing something in here ?

    Thanks,


Log in to reply