首页 文章

'QwtPlotCurve'中没有名为'setRawData'的成员 - 将Qt 4.7转换为Qt 5.8

提问于
浏览
0

我需要 convert Qt legacy code from 4.7 to 5.8 ,我在Qt Creator 4.2.1 Clang 7.0(Apple)64bit中有编译错误 .

Looking in .cpp file

#include "mpiChartCurve.h"
#include <qwt_plot_curve.h>


mpiChartCurve::mpiChartCurve(QwtPlot *chart_):
    m_chart(chart_),
    m_curve(new QwtPlotCurve())
{
}

mpiChartCurve::~mpiChartCurve()
{
    // be default qwt will delete the curve when it is destroyed
    // only delete the curve when detach is called
}

void mpiChartCurve::detach()
{
    m_curve->detach();

    // hack for now?  qwt doesn't seem to redraw properly until a curve is attached after a detachment, so attach dummy
    QVector<double> x, y;
    m_curve->setRawData(x.constData(), y.constData(), 0); // JDL convert Qt4 to Qt5  BROKE
    m_curve->attach(m_chart);
    m_curve->detach();

    delete m_curve;
    m_curve = 0;
}


void mpiChartCurve::attach()
{
    if (!m_curve)
        return;

    m_curve->setRawData(m_xData.constData(),m_yData.constData(), count()); // JDL convert Qt4 to Qt5  BROKE
    m_curve->attach(m_chart);
}

2 Errors in .cpp

../src/usercontrols/mpiChartCurve.cpp:23:14:1165364_m_curve-> setRawData(x.constData(),y.constData(),0); // JDL将Qt4转换为Qt5 BROKE ~~~~~~~ ^

../src/usercontrols/mpiChartCurve.cpp:37:14: error: no member named 'setRawData' in 'QwtPlotCurve' m_curve-> setRawData(m_xData.constData(),m_yData.constData(),count()); // JDL将Qt4转换为Qt5 BROKE ~~~~~~~ ^

2 errors generated make:*** [mpiChartCurve.o]错误1 21:12:40:进程"/usr/bin/make"退出代码2.构建/部署项目mypersonalindex时出错(工具包:Desktop Qt 5.8.0 clang 64bit)执行步骤"Make"时

Qt5文档提到 setRawData

QByteArray &    setRawData(const char *data, uint size)

我在QByteArray的doc中注意到了这个评论

(废弃)运算符const char *()const

我的C技能非常有限,您是否看到任何可以将其从Qt4转换为Qt5的小调整 . ......那么替代品是什么?

1 回答

  • 0

    setRawData不是QwtPlotCurve的成员函数 . 它是QByteArray的成员函数,它只接受2个参数 . 将setRawData更改为setRawSamples,setRawSamples是QwtPlotCurve的成员函数,并接受您要查找的三个参数 .

    固定版本

    #include "mpiChartCurve.h"
    #include <qwt_plot_curve.h>
    
    
    mpiChartCurve::mpiChartCurve(QwtPlot *chart_):
        m_chart(chart_),
        m_curve(new QwtPlotCurve())
    {
    }
    
    mpiChartCurve::~mpiChartCurve()
    {
        // be default qwt will delete the curve when it is destroyed
        // only delete the curve when detach is called
    }
    
    void mpiChartCurve::detach()
    {
        m_curve->detach();
    
        // hack for now?  qwt doesn't seem to redraw properly until a curve is attached after a detachment, so attach dummy
        QVector<double> x, y;
        m_curve->setRawSamples(x.constData(), y.constData(), 0); // JDL convert Qt4 to Qt5  BROKE
        m_curve->attach(m_chart);
        m_curve->detach();
    
        delete m_curve;
        m_curve = 0;
    }
    
    
        void mpiChartCurve::attach()
    {
        if (!m_curve)
            return;
    
        m_curve->setRawSamples(m_xData.constData(),m_yData.constData(), count()); // JDL convert Qt4 to Qt5  BROKE
        m_curve->attach(m_chart);
    }
    

相关问题