I need to convert Qt legacy code from 4.7 to 5.8, I have a compilation error in 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: error: no member named 'setRawData' in 'QwtPlotCurve' m_curve->setRawData(x.constData(), y.constData(), 0); // JDL convert Qt4 to 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 convert Qt4 to Qt5 BROKE ~~~~~~~ ^
2 errors generated make: *** [mpiChartCurve.o] Error 1 21:12:40: The process "/usr/bin/make" exited with code 2. Error while building/deploying project mypersonalindex (kit: Desktop Qt 5.8.0 clang 64bit) When executing step "Make"
The Qt5 Docs mentioned setRawData
QByteArray & setRawData(const char *data, uint size)
I did notice this comment in doc for QByteArray
(obsolete) operator const char *() const
My C++ skill is pretty limited, do you see any minor tweaks that could convert this from Qt4 to Qt5. ... so what is the replacement?
setRawData is not a member function of QwtPlotCurve. It is a member function of QByteArray and it only accepts 2 arguments. Change setRawData to setRawSamples, setRawSamples is a member function of QwtPlotCurve and accepts the three arguments you're looking for.
Fixed version
#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);
}