【发布时间】:2017-03-13 14:17:29
【问题描述】:
我需要将 Qt 遗留代码从 4.7 转换为 5.8,我在 Qt Creator 4.2.1 Clang 7.0(Apple) 64bit 中出现编译错误。我正在使用最新的 Qwt 6.1.3
查看 .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));
.cpp 中的 2 个错误
../src/ui/frmMainChart_UI.cpp:18:26: 错误:在“QwtPlotLayout”中没有名为“setMargin”的成员 图表->plotLayout()->setMargin(20); // BROKE 将 Qt4 转换为 Qt5
../src/ui/frmMainChart_UI.cpp:19:23: 错误:'mpiPlotZoomer' 的初始化没有匹配的构造函数 chartZoomer = new mpiPlotZoomer(chart->canvas()); // BROKE 将 Qt4 转换为 Qt5
^
生成 5 个警告和 2 个错误 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
【问题讨论】:
-
你在 Qt 4.7 中使用的是什么版本的 Qwt?
-
奇怪,带有 Qt 4.7 的 Qwt 似乎是 2011 年的 Qwt 5.5.5,(但最新的 Qwt 有这个现在与 Qt5.8 一起安装的 1.6.3 版本)
-
最新的 qwt 版本是 6.1.3,而不是 1.6.3:qwt.sourceforge.net/index.html
-
mpiChart.cpp没用,mpiChart.h会有所帮助。 -
mpiPlotZoomer.cpp也无用,mpiPlotZoomer.h会有所帮助