[英]No member named 'setMargin' in 'QwtPlotLayout' - Convert Qt4.7 to Qt5.8
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. 我需要将Qt旧版代码从4.7转换为5.8 ,我在Qt Creator 4.2.1 Clang 7.0(Apple)64bit中遇到编译错误。 I'm using latest Qwt 6.1.3
我正在使用最新的Qwt 6.1.3
Looking in .cpp file 在.cpp文件中查找
#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 .cpp中有2个错误
../src/ui/frmMainChart_UI.cpp:18:26: error: no member named 'setMargin' in 'QwtPlotLayout' chart->plotLayout()->setMargin(20); ../src/ui/frmMainChart_UI.cpp:18:26: 错误:在'QwtPlotLayout'chart- > plotLayout()-> setMargin(20)中没有名为'setMargin'的成员 ; // BROKE convert Qt4 to Qt5
//将Qt4转换为Qt5
../src/ui/frmMainChart_UI.cpp:19:23: error: no matching constructor for initialization of 'mpiPlotZoomer' chartZoomer = new mpiPlotZoomer(chart->canvas()); ../src/ui/frmMainChart_UI.cpp:19:23: 错误:没有匹配的构造函数来初始化' mpiPlotZoomer'chartZoomer = new mpiPlotZoomer(chart-> canvas()); // BROKE convert Qt4 to Qt5
//将Qt4转换为Qt5
^
5 warnings and 2 errors generated make: *** [frmMainChart_UI.o] Error 1 06:58:25: 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" 06:58:25: Elapsed time: 00:01. 生成5条警告和2条错误 :*** [frmMainChart_UI.o]错误1 06:58:25:进程“ / usr / bin / make”以代码2退出。构建/部署项目mypersonalindex(工具包:桌面)时出错Qt 5.8.0 clang 64位)执行步骤“ Make”时06:58:25:经过的时间:00:01。
The Qwt 6.1.3 Docs has member function http://qwt.sourceforge.net/class_qwt_plot_layout.html Qwt 6.1.3文档具有成员函数http://qwt.sourceforge.net/class_qwt_plot_layout.html
void setCanvasMargin (int margin, int axis=-1)
But NO Member Function being used 但是没有使用成员函数
setMargin
My C++ skill is pretty limited, do you see any minor tweaks that could convert this from Qt4 to Qt5. 我的C ++技能非常有限,您是否看到任何细微的调整都可以将其从Qt4转换为Qt5。 ... so what is the replacement?
...那么什么是替代品?
Looking at mpiChart.h likely relates to canvas() error 查看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
And Looking in mpiPlotZoomer.h relates to canvas() error 并且在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
As the setMargin
function has been removed between Qwt version you were using for Qt 4.7 and Qwt 1.6.3 you are using with 5.8, you have no other choice than: 由于已在用于Qt 4.7的Qwt版本和用于5.8的Qwt 1.6.3之间删除了
setMargin
函数,因此您别无选择:
setMargin
calls by setCanvasMargin
if that fits your needs setCanvasMargin
替换setMargin
调用 setMargin
calls setMargin
调用 Try both, and see which one looks the best when displaying the GUI. 尝试两者,并在显示GUI时查看哪个看起来最好。
For the canvas()
error, it's hard to tell without seeing mpiChart
and mpiPlotZoomer
declaration. 对于
canvas()
错误,很难看到mpiChart
和mpiPlotZoomer
声明。 However, I'll give it a try: 但是,我将尝试一下:
canvas()
used to return a QwtPlotCanvas*
in the past. canvas()
过去用于返回QwtPlotCanvas*
。 For recent versions of Qwt it returns a QWidget*
. 对于最新版本的Qwt,它将返回
QWidget*
。 So if your mpiPlotZoomer
constructor expects a QwtPlotCanvas*
as parameter, you'll have to: 因此,如果您的
mpiPlotZoomer
构造函数期望使用QwtPlotCanvas*
作为参数,则必须:
mpiPlotZoomer
parameters type from QwtPlotCanvas*
by QWidget*
. QWidget*
替换mpiPlotZoomer
QwtPlotCanvas*
的mpiPlotZoomer
参数类型。 May work if the guy who wrote the mpiPlotZoomer
class does not actually use and QwtPlotCanvas
members/attributes (he may only use it for parenting purpose) mpiPlotZoomer
类的人没有实际使用QwtPlotCanvas
成员/属性,他可能会工作(他只能将其用于育儿目的) mpiPlotZoomer(chart->canvas());
mpiPlotZoomer(chart->canvas());
by mpiPlotZoomer( qobject_cast<QwtPlotCanvas*>( chart->canvas() ) );
mpiPlotZoomer( qobject_cast<QwtPlotCanvas*>( chart->canvas() ) );
which will hoepfully work fine.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.