我需要将Qt遗留代码从4.7转换为5.8 ,我在Qt Creator 4.2.1 Clang 7.0(Apple)64bit中有编译错误。
查看.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:错误:没有名为&#39; setRawData&#39;在&#39; QwtPlotCurve&#39; m_curve-&gt; setRawData(x.constData(),y.constData(),0); // JDL将Qt4转换为Qt5 BROKE ~~~~~~~ ^
../ src / usercontrols / mpiChartCurve.cpp:37:14:错误:没有名为&#39; setRawData&#39;在&#39; QwtPlotCurve&#39; m_curve-&gt; setRawData(m_xData.constData(),m_yData.constData(),count()); // JDL将Qt4转换为Qt5 BROKE ~~~~~~~ ^
生成2个错误 make:*** [mpiChartCurve.o]错误1 21:12:40:过程&#34; / usr / bin / make&#34;退出代码2。 构建/部署项目mypersonalindex时出错(工具包:Desktop Qt 5.8.0 clang 64bit) 执行步骤&#34;制作&#34;
Qt5文档提到了 setRawData
QByteArray & setRawData(const char *data, uint size)
我在QByteArray的文档中注意到了这条评论
(废弃)运算符const char *()const
我的C ++技能非常有限,您是否看到任何可以将其从Qt4转换为Qt5的小调整。 ......那么替代品是什么?
答案 0 :(得分: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);
}