我需要 convert Qt legacy code from 4.7 to 5.8 ,我在Qt Creator 4.2.1 Clang 7.0(Apple)64bit中有编译错误 . 我正在使用最新的Qwt 6.1.3
Looking in .cpp file
#include "frmMainChart_UI.h"
#include <QHeaderView>
#include <qwt_plot_layout.h>
#include <qwt_legend.h>
#include "mpiDateScale.h"
#include "mpiPercentScale.h"
void frmMainChart_UI::setupUI(QWidget *parent_)
{
frmMainTableViewTree_UI::setupUI(QMap<int, QString>(), false, parent_);
delete frmMainTableViewTree_UI::tableCopy;
delete frmMainTableViewTree_UI::table;
chart = new mpiChart(widget);
chart->setAxisScaleDraw(QwtPlot::xBottom, new mpiDateScale());
chart->setAxisScaleDraw(QwtPlot::yLeft, new mpiPercentScale());
chart->plotLayout()->setCanvasMargin(20);
chart->plotLayout()->setMargin(20); // BROKE convert Qt4 to Qt5
chartZoomer = new mpiPlotZoomer(chart->canvas()); // BROKE convert Qt4 to Qt5
chartLegend = new QwtLegend(chart);
chart->insertLegend(chartLegend, QwtPlot::RightLegend);
QLinearGradient grad(0, 0, 1, 1);
grad.setCoordinateMode(QGradient::StretchToDeviceMode);
grad.setColorAt(0, Qt::white);
grad.setColorAt(1, QColor(220, 220, 220));
2 Errors in .cpp
../src/ui/frmMainChart_UI.cpp:18:26:1165378_ chart-> plotLayout() - > setMargin(20); // BROKE将Qt4转换为Qt5
../src/ui/frmMainChart_UI.cpp:19:23: error: no matching constructor for initialization of 'mpiPlotZoomer' chartZoomer = new mpiPlotZoomer(chart-> canvas()); // BROKE将Qt4转换为Qt5
^
5 warnings and 2 errors generated make:*** [frmMainChart_UI.o]错误1 06:58:25:进程"/usr/bin/make"退出代码2.构建/部署项目mypersonalindex时出错(工具包:Desktop Qt 5.8.0 clang 64bit)执行步骤"Make" 06 :58:25:经过的时间:00:01 .
Qwt 6.1.3 Docs 有成员函数http://qwt.sourceforge.net/class_qwt_plot_layout.html
void setCanvasMargin (int margin, int axis=-1)
但是没有使用会员功能
setMargin
我的C技能非常有限,您是否看到任何可以将其从Qt4转换为Qt5的小调整 . ......那么替代品是什么?
查看mpiChart.h可能与canvas()错误有关
#ifndef MPICHART_H
#define MPICHART_H
#include "qwt_plot.h"
class mpiChart : public QwtPlot
{
Q_OBJECT
public:
mpiChart(QWidget *parent_ = 0):
QwtPlot(parent_)
{}
public slots:
void exportChart();
};
#endif // MPICHART_H
并且在mpiPlotZoomer.h中查找与canvas()错误有关
#ifndef MPIPLOTZOOMER_H
#define MPIPLOTZOOMER_H
#include <qwt_plot_zoomer.h>
#include <qwt_plot_canvas.h> // JDL convert Qt4 to Qt5
#include <qwt_compat.h> // JDL convert Qt4 to Qt5
class mpiPlotZoomer: public QwtPlotZoomer
{
public:
mpiPlotZoomer(QwtPlotCanvas *canvas_):
QwtPlotZoomer(canvas_, false)
{
setTrackerMode(AlwaysOn);
}
virtual QwtText trackerText(const QwtDoublePoint &pos_) const;
};
#endif // MPIPLOTZOOMER_H
1 回答
由于你使用Qt 4.7和你使用的Qwt 1.6.3的Qwt版本之间的
setMargin
功能被删除了,你别无选择:如果符合您的需要,请将
setMargin
替换为setMargin
或者,删除
setMargin
来电尝试两者,并在显示GUI时查看哪一个看起来最好 .
对于
canvas()
错误,如果没有看到mpiChart
和mpiPlotZoomer
声明,很难说清楚 . 但是,我会试一试:canvas()
过去用于返回QwtPlotCanvas*
. 对于Qwt的最新版本,它返回QWidget*
. 因此,如果mpiPlotZoomer
构造函数需要QwtPlotCanvas*
作为参数,则必须:将
QwtPlotCanvas*
的mpiPlotZoomer
参数类型替换为QWidget*
. 如果编写mpiPlotZoomer
类的人实际上没有使用和QwtPlotCanvas
成员/属性(他可能只用于育儿目的)可能会有效或者用
mpiPlotZoomer( qobject_cast<QwtPlotCanvas*>( chart->canvas() ) );
替换mpiPlotZoomer(chart->canvas());
,这将很好地工作 .