Daniil Solodukhin
Daniil Solodukhin

Reputation: 53

How to plot with QwtPlot from Qt slot?

Good time of day! I have a question you'll maybe find silly and obvious, but i've already broke my head trying to solve this.

I want to plot some curve by pressing a QPushButton. I wrote the slot and connected it to the corresponding signal of this button. But when I click on it, nothing happens on the plot, although this function executes, and it can be viewed on the debugger and qDebug() output.

On the other hand, if you call this function directly, and not as a slot, it works perfectly. The only difference is the calling method: as a slot in first case and as a method in the second case.

Some code examples:

//Slot 
void MainWindow::buttonClick()
{
    qDebug() << "Enter";
    XRDDataReader *xrdr = new XRDDataReader();
    xrdr->fromFile("/home/hippi/Документы/Sources/Qt/49-3.xy");

    ui->plot->plotXRD(xrdr->xValues(), xrdr->yValues());
    qDebug() << "Quit";
}

void Plotter::plotXRD(QVector<double> x, QVector<double> y)
{
    QwtPlotCurve *curve = new QwtPlotCurve();
    curve->setRenderHint
                ( QwtPlotItem::RenderAntialiased, true );
    curve->setPen(Qt::black, 2);

    curve->setSamples(x,y);
    curve->attach(mainPlot);
}

Upvotes: 1

Views: 452

Answers (1)

Uwe
Uwe

Reputation: 725

As long as autoreplotting is not enabled, you have to call replot to make changes happen.

Upvotes: 1

Related Questions