Error: no matching function for call to ’QwtPlotCurve::setData(int*)’



  • Hi,

    I use this function to plot any data...

    @void Plot::populate()
    {
    // Insert new curves
    QwtPlotCurve *cSin = new QwtPlotCurve("y = sin(x)");
    cSin->setRenderHint(QwtPlotItem::RenderAntialiased);
    cSin->setLegendAttribute(QwtPlotCurve::LegendShowLine, true);
    cSin->setPen(QPen(Qt::red));
    cSin->attach(this);

    QwtPlotCurve *cCos = new QwtPlotCurve("y = cos(x)");
    cCos->setRenderHint(QwtPlotItem::RenderAntialiased);
    cCos->setLegendAttribute(QwtPlotCurve::LegendShowLine, true);
    cCos->setPen(QPen(Qt::blue));
    cCos->attach(this);
    
    // Create sin and cos data
    //cSin->setData(new FunctionData(::sin));
    //cCos->setData(new FunctionData(::cos));
    
    //template <typename T>
    //QwtSeriesData<T> *ptrDensity;
    //QwtSeriesData<T> *ptrPressure;
    int density= 20;
    int pressure= 50;
    //ptrPressure= pressure;
    //ptrDensity= density;
    cSin->setData(&density);
    cCos->setData(&pressure);
    
    // 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 = 2 * pi
    QwtPlotMarker *mX = new QwtPlotMarker();
    mX->setLabel(QString::fromLatin1("x = 2 pi"));
    mX->setLabelAlignment(Qt::AlignLeft | Qt::AlignBottom);
    mX->setLabelOrientation(Qt::Vertical);
    mX->setLineStyle(QwtPlotMarker::VLine);
    mX->setLinePen(QPen(Qt::black, 0, Qt::DashDotLine));
    mX->setXValue(2.0 * M_PI);
    mX->attach(this);
    

    }@

    but I receive the error message "no matching function for call to 'QwtPlotCurve::setData(int*)'"
    I'm new in c++, could anywhere explain me what I make wrong?

    Thanks in advanced and best regards

    Antonio



  • Here is some help: "http://qwt.sourceforge.net/class_qwt_plot_curve.html":http://qwt.sourceforge.net/class_qwt_plot_curve.html

    According to this setData takes as argument QwtSeriesData< QPointF* >:
    @
    void setData (QwtSeriesData< QPointF > *)
    @

    Best regards!
    Robert



  • Thanks, I try now wit the function

    @void setSamples( const double *xData, const double *yData, int size);@

    it work well.

    but now I have implemented another function that pass a value from a Modbus Slave.

    @Plot::setPlotValue(int value)
    {
    QwtPlotCurve *plotGPS;
    cntX++;
    plotGPS->setSamples(&cntX, &value, sizeof(cntX+value));
    }@

    the function call is in another file --> modbusadapter.h, I include in the modbusadapter.h file follows:

    @#include "mainwindow.h" // in this header are the other class
    ...
    ...
    ...
    class ....
    {
    ...
    ...
    Plot *plotValue; // class declaration
    }@

    and the call implementation in modbusadapter.cpp:

    @plotValue->setPlotValue(data);@

    and in the mainwindow.h:

    @void setPlotValue(int value);@

    I receive the following error:

    ISO C++ forbids declaration of 'Plot' with no type

    her the Plot class:

    @class Plot : public QwtPlot
    {
    public:
    Plot( QWidget *parent = NULL);

    protected:
    virtual void resizeEvent( QResizeEvent * );

    private:
    void populate();
    void updateGradient();
    void setPlotValue(int value);
    unsigned int cntX;
    };@

    What does mean that?

    Antonio



  • Looks like compiler can't find any info about your new class

    Here is some words which can explain You this problem: "Google help ;)":http://www.qtcentre.org/threads/38152-error-ISO-C-forbids-declaration-of-obj-with-no-type and here: "Google again":http://www.allegro.cc/forums/thread/594307.

    Robert


  • Moderators

    Your original post line 27, 28 you are using setData for instance with density. Since you declare density as integer before and you use it as :
    @
    cSin->setData(&density);
    @
    you get a pointer to your integer and that method is not defined as already outlined by poor_robert

    [quote author="Antonio2178" date="1337970635"]
    @Plot::setPlotValue(int value)
    {
    QwtPlotCurve *plotGPS;
    cntX++;
    plotGPS->setSamples(&cntX, &value, sizeof(cntX+value));
    }@
    [/quote]

    Here have for sure also a problem. You create a pointer named plotGPS of QwtPlotCurve, but it simply points somewhere you need to allocate memory. Otherwise you will get a crash.

    [quote author="Antonio2178" date="1337970635"]
    @#include "mainwindow.h" // in this header are the other class
    ...
    ...
    ...
    class ....
    {
    ...
    ...
    Plot *plotValue; // class declaration
    }@

    and the call implementation in modbusadapter.cpp:

    @plotValue->setPlotValue(data);@

    and in the mainwindow.h:

    @void setPlotValue(int value);@

    I receive the following error:

    ISO C++ forbids declaration of 'Plot' with no type

    her the Plot class:

    @class Plot : public QwtPlot
    {
    public:
    Plot( QWidget *parent = NULL);

    protected:
    virtual void resizeEvent( QResizeEvent * );

    private:
    void populate();
    void updateGradient();
    void setPlotValue(int value);
    unsigned int cntX;
    };@
    [/quote]

    where is class Plot declared is that in mainwindow.h ?



  • yes the class PLot is in the mainwindow.h...

    that was a beginner c++ error that I make, likes this: !http://www.qtcentre.org/threads/38152-error-ISO-C-forbids-declaration-of-obj-with-no-type()!

    but now I make two new files plot.cpp and plot.h.

    plot.h

    @#ifndef PLOT_H
    #define PLOT_H

    #include <qapplication.h>
    #include <qlayout.h>
    #include <qwt_plot.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>

    class Plot : public QwtPlot
    {
    public:
    Plot( QWidget *parent = NULL);

    protected:
    virtual void resizeEvent( QResizeEvent * );

    private:
    void populate();
    void updateGradient();
    void setPlotValue(double value);
    double cntX;
    };

    /*
    class FunctionData: public QwtSyntheticPointData
    {
    public:
    FunctionData(double(*y)(double)): QwtSyntheticPointData(100), d_y(y)
    {
    }

    virtual double y(double x) const
    {
        return d_y(x);
    }
    

    private:
    double(*d_y)(double);
    };
    */

    #endif // PLOT_H@

    plot.cpp

    @#include "plot.h"

    Plot::Plot(QWidget *parent):
    QwtPlot( parent )
    {
    cntX= 0.0;

    .....
    }

    void Plot::populate()
    {
    // Insert new curves
    QwtPlotCurve *cSin = new QwtPlotCurve("y = sin(x)");
    cSin->setRenderHint(QwtPlotItem::RenderAntialiased);
    cSin->setLegendAttribute(QwtPlotCurve::LegendShowLine, true);
    cSin->setPen(QPen(Qt::red));
    cSin->attach(this);

    QwtPlotCurve *cCos = new QwtPlotCurve("y = cos(x)");
    cCos->setRenderHint(QwtPlotItem::RenderAntialiased);
    cCos->setLegendAttribute(QwtPlotCurve::LegendShowLine, true);
    cCos->setPen(QPen(Qt::blue));
    cCos->attach(this);
    
    // Create sin and cos data
    //cSin->setData(new FunctionData(::sin));
    //cCos->setData(new FunctionData(::cos));
    
    //double density= 20.0;
    //double pressure= 50.0;
    //cSin->setSamples(&density, &pressure, sizeof(density+pressure));
    
    // 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 = 2 * pi
    QwtPlotMarker *mX = new QwtPlotMarker();
    mX->setLabel(QString::fromLatin1("x = 2 pi"));
    mX->setLabelAlignment(Qt::AlignLeft | Qt::AlignBottom);
    mX->setLabelOrientation(Qt::Vertical);
    mX->setLineStyle(QwtPlotMarker::VLine);
    mX->setLinePen(QPen(Qt::black, 0, Qt::DashDotLine));
    mX->setXValue(2.0 * M_PI);
    mX->attach(this);
    

    }

    void Plot::setPlotValue(double value)
    {
    QwtPlotCurve *plotGPS;
    cntX++;
    plotGPS->setSamples(&cntX, &value, sizeof(cntX+value));
    }

    void Plot::updateGradient()
    {
    .......
    }

    void Plot::resizeEvent( QResizeEvent *event )
    {
    .......
    }@

    and here in the modbusadapter.h I include plot.h and declare a pointer to class plot

    @#ifndef MODBUSADAPTER_H
    #define MODBUSADAPTER_H

    #include <QObject>
    #include "modbus.h"
    #include "registersmodel.h"
    #include "rawdatamodel.h"
    #include <QTimer>
    #include "eutils.h"

    #include "plot.h"

    //class Plot;

    class ModbusAdapter : public QObject
    {
    Q_OBJECT
    public:
    explicit ModbusAdapter(QObject *parent = 0);

     void busMonitorRequestData(uint8_t * data,uint8_t dataLen);
     void busMonitorResponseData(uint8_t * data,uint8_t dataLen);
    
     void modbusConnectRTU(QString port, int baud, QChar parity, int dataBits, int stopBits);
     void modbusConnectTCP(QString ip, int port);
     void modbusDisConnect();
     void modbusRequestData(int slave, int functionCode, int startAddress, int noOfItems);
     RegistersModel *regModel;
     Plot *plotValue;
     RawDataModel *rawModel;
     bool isConnected();
    

    private:
    modbus_t * m_modbus;
    bool m_connected;
    bool m_RTUSelected;

    signals:

    public slots:

    };

    #endif // MODBUSADAPTER_H
    @

    in the modbusadapter.cpp I call the function setPlotValue

    @int data = is16Bit ? dest16[i] : dest[i];
    regModel->setValue(i,data,is16Bit);

    plotValue->setPlotValue((double)data);@

    I could compile the program well but it crash when I want start it,
    I try to allocate memory in this way:

    @plotValue = malloc(Plot);@

    or

    @Plot *plotValue = new Plot();@

    could I make this so?



  • and at the end of the function can I insert this to free the memory?

    @free(plotValue );@


  • Moderators

    I personally prefer to use "new" and "delete". The more older styles are "malloc" and "free". In principle you may both style. You may even use both in the same program, if I am not mistaken.
    However, when doing so, you are ill-advised. Decide which style to use and keep to it.

    Because memory allocated with "malloc" and its side-forms requires a "free" to release the memory. Memory allocated with "new" requires "delete".

    For use with C++ it is better to use "new" and "delete" because those will take advantage of the constructors and destructors for the class. With malloc you have to do it on your own, which is quite a bit of nuisance.

    [quote author="Antonio2178" date="1338064102"]
    I could compile the program well but it crash when I want start it,
    I try to allocate memory in this way:

    @plotValue = malloc(Plot);@

    [/quote]

    This above statement will not work you have to give the size of the memory to be allocated. As written here it give a compile error.

    [quote author="Antonio2178" date="1338064102"]

    @Plot *plotValue = new Plot();@

    [/quote]

    This should compile and it is the more suitable style for C++ as explained above.



  • yes it work now well. it was a problem with the toolchain and dll...

    I installed Qt Creator new and copied all dll in windows/system folder...

    thanks all

    Antonio


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.