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

No member named 'setRawData' in 'QwtPlotCurve' - Convert Qt 4.7 to Qt 5.8

我需要将 Qt 遗留代码从 4.7 转换为 5.8,我在 Qt Creator 4.2.1 Clang 7.0(Apple) 64 位中遇到编译错误。

正在.cpp 文件中查找

#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);
}

.cpp 中有 2 个错误

../src/usercontrols/mpiChartCurve.cpp:23:14: 错误:'QwtPlotCurve' 中没有名为 'setRawData' 的成员 m_curve->setRawData(x.constData(), y.constData(), 0); // JDL 将 Qt4 转换为 Qt5 BROKE ~~~~~~~ ^

../src/usercontrols/mpiChartCurve.cpp:37:14: 错误:'QwtPlotCurve' 中没有名为 'setRawData' 的成员 m_curve->setRawData(m_xData.constData(),m_yData.constData(), count()); // JDL 将 Qt4 转换为 Qt5 BROKE ~~~~~~~ ^

产生了 2 个错误 make: *** [mpiChartCurve.o] 错误 1 21:12:40:进程“/usr/bin/make”已退出,代码为 2。 building/deploying 项目 mypersonalindex 时出错(工具包:桌面 Qt 5.8.0 clang 64 位) 当执行步骤"Make"

Qt5 文档提到 setRawData

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

我确实在 QByteArray 的文档中注意到了这条评论

(过时)运算符 const char *() const

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

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);
}