Quantcast
Channel: Installation and Deployment
Viewing all articles
Browse latest Browse all 22112

Problem with qwtPlot / not matching function for call to...

$
0
0
Hi all, I wrote a application that plot data with the qwtPlot library. It will not work fine. First I try to plot xData and yData in a while loop 5 times with function populate() in plot.cpp. When I call the function populate() at the end from the constructor Plot::Plot…, the plot are correctly. But when I call the function populate() from the module modbusadapter.cpp, I became an error message: no matching function for call to ‘Plot::Plot(ModbusAdapter* const)’ candidates are: Plot::Plot(QWidget*) note: Plot::Plot(const Plot&) I receive the error only when I allocate memory for plot object in this form: plotNewDensity=new Plot(this); without the attribute ‘this’, I can compile, but when I call function populate() in modbusadapter.cpp (after modbus response), I can see in debug mode that the code jumps in populate(), but without plots… Here any code segments: plot.h #ifndef PLOT_H #define PLOT_H   #include <qapplication.h> #include <qlayout.h> #include <qwt_plot.h> #include <qwt_plot_grid.h> #include <qwt_plot_marker.h> #include <qwt_plot_curve.h> #include <qwt_legend.h> #include <qwt_series_data.h> #include <qwt_plot_canvas.h> #include <qwt_plot_panner.h> #include <qwt_plot_magnifier.h> #include <qwt_text.h> #include <qwt_math.h> #include <math.h>   #define SIZE 15   class Plot : public QwtPlot {     Q_OBJECT   public:     Plot( QWidget *parent = NULL);     ~Plot();     void setPlotValue(double value);     void populate();   protected:     virtual void resizeEvent( QResizeEvent * );   private:     //void populate();     void updateGradient();     double cntX;     QwtPlotCurve *density;     double xData[SIZE];     double yData[SIZE];   public slots:     void addNewValue(double value);     //void populate();   signals:   }; #endif // PLOT_H plot.cpp #include "plot.h"   Plot::Plot(QWidget *parent):     QwtPlot( parent ) {     xData[0] = 0;     yData[0] = 0;       // Insert new density curve     density = new QwtPlotCurve("y = density");     //density->setRenderHint(QwtPlotItem::RenderAntialiased);     density->setStyle(QwtPlotCurve::Lines);     density->setLegendAttribute(QwtPlotCurve::LegendShowLine, true);     density->setPen(QPen(Qt::red));     density->attach(this);       // Draw grid     QwtPlotGrid *grid = new QwtPlotGrid();     grid->setPen(QPen(Qt::gray, 0.0, Qt::DotLine));     grid->enableX(true);     grid->enableXMin(true);     grid->enableY(true);     grid->enableYMin(false);     grid->attach(this);       // Insert markers     //  ...a horizontal line at y = 0...     QwtPlotMarker *mY = new QwtPlotMarker();     mY->setLabel(QString::fromLatin1("y = 0"));     mY->setLabelAlignment(Qt::AlignRight|Qt::AlignTop);     mY->setLineStyle(QwtPlotMarker::HLine);     mY->setYValue(0.0);     mY->attach(this);       //  ...a vertical line at x = 0...     QwtPlotMarker *mX = new QwtPlotMarker();     mX->setLabel(QString::fromLatin1("x = 0"));     mX->setLabelAlignment(Qt::AlignLeft | Qt::AlignBottom);     mX->setLabelOrientation(Qt::Vertical);     mX->setLineStyle(QwtPlotMarker::VLine);     mX->setLinePen(QPen(Qt::black, 0, Qt::DashDotLine));     mX->setXValue(0.0);     mX->attach(this);       // init private member     //cntX= 0.0;     // init function setPlotValue     //setPlotValue(0.0);     //plotGPS=new QwtPlotCurve();       // panning with the left mouse button     (void) new QwtPlotPanner( canvas() );       // zoom in/out with the wheel     (void) new QwtPlotMagnifier( canvas() );       setAutoFillBackground( true );     setPalette( QPalette( QColor( 165, 193, 228 ) ) );     updateGradient();       setTitle("A Simple QwtPlot Demonstration");     insertLegend(new QwtLegend(), QwtPlot::RightLegend);       // axes     setAxisTitle(xBottom, "x -->" );     setAxisScale(xBottom, 0.0, 10.0);       setAxisTitle(yLeft, "y -->");     setAxisScale(yLeft, -1.0, 1.0);       // canvas     canvas()->setLineWidth( 1 );     canvas()->setFrameStyle( QFrame::Box | QFrame::Plain );     canvas()->setBorderRadius( 15 );       QPalette canvasPalette( Qt::white );     canvasPalette.setColor( QPalette::Foreground, QColor( 133, 190, 232 ) );     canvas()->setPalette( canvasPalette );       //populate();    // when I call here, the plots are correctly... }   Plot::~Plot() {   }   void Plot::populate() {     qWarning()<<  "Plot : populate()";       double maxD = 0;     double minD = 1;     double maxS = 0;     double minS = 1;       double dens = 2.0;     unsigned int sample = 0;     unsigned int x = 0;     unsigned int y = 0;       while(sample < 5)     {         xData[x++]= sample;         yData[y++]= dens;           setAxisScale(xBottom, (int)xData[dataCount-1]-iHistorySize, (int)xData[dataCount-1]+1);         setAxisScale(yLeft, (int)min-1, (int)max+1);           maxS = sample;         minS = sample++;         maxD = dens;         minD = dens++;           setAxisScale(xBottom, (int)minS-1, (int)maxS+1);         setAxisScale(yLeft,   (int)minD-1, (int)maxD+1);           density->setSamples(xData, yData, sample);         // Call "replot()" to refresh plot displaying         replot();     } } ... ... ...

Viewing all articles
Browse latest Browse all 22112

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>